【问题标题】:Recyclerview height is as big as screenRecyclerview高度和屏幕一样大
【发布时间】:2016-10-27 20:39:53
【问题描述】:

伙计们,我有一个简单的回收站视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">

<android.support.v7.widget.RecyclerView
    android:id="@+id/realm_recycler_view"
    android:background="@null"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

</RelativeLayout>

但它没有按应有的方式显示。我希望它像普通的列表视图一样显示(高度明智),但不知何故它会占用每个 recyclerview 项目的整个屏幕。 (所以它和屏幕一样大)

我尝试了 wrap_content 和 match_parent 都没有成功..

关于如何解决这个问题的任何建议?

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView =  inflater.inflate(R.layout.fragment_main_activity_fragment_two, container, false);

    recyclerView = (RecyclerView) rootView.findViewById(R.id.realm_recycler_view);

    setupRecyclerView();
    return rootView;
}

public void setupRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(new gradeRealmAdapter(this, realm.where(Grade.class).findAllAsync()));
    recyclerView.setHasFixedSize(true);
    recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    recyclerView.setNestedScrollingEnabled(false);
}

【问题讨论】:

  • 我认为您不需要布局上的 weightSum="1" 属性规范。没有它你可以试试吗?
  • 不,没有帮助@milosmns

标签: java android android-recyclerview realm


【解决方案1】:

您还没有向我们展示列表元素的布局。看起来您的元素布局高度中有match_parent。请同时发布您的 RecyclerView 项目布局。

【讨论】:

  • 这不是答案,应该作为评论发布。
  • 很遗憾,我没有足够的声望点来添加 cmets。
  • 这就是诀窍!列表元素在其高度而不是 wrap_content 上设置在 match_parent 上。非常感谢
猜你喜欢
  • 2017-12-07
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-19
  • 1970-01-01
  • 2018-09-16
  • 2022-01-16
  • 1970-01-01
相关资源
最近更新 更多