Recyclerview高度与屏幕一样大

时间:2016-10-27 20:39:54

标签: java android android-recyclerview realm

伙计我有一个简单的回收者视图

<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);
}

1 个答案:

答案 0 :(得分:2)

您尚未向我们展示列表元素的布局。看起来您的元素布局高度为match_parent。请发布您的RecyclerView项目布局。