0
我目前使用RecyclerView
来显示卡片列表。 它与ListView
和ArrayListAdapter
很好,但现在发生了一些奇怪的事情。LinearLayoutManager创建卡片之间的空间
当列表第一次加载时,显示的3张第一张卡片显示正确。但是没有出现的那些在它们每一个下面都有巨大的空间。
它与LayoutManager
有关,因为Android文档说它是管理显示与否以及如何显示它的实体。
就我而言,我使用的是LinearLayoutManager
。
这里是在我的初始化的一些代码我Fragment
:
layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
listAdapter = new EventsListAdapter(events);
recyclerView.setAdapter(listAdapter);
recyclerView.setLayoutManager(layoutManager);
这里的RecyclerView
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/events_list_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</RelativeLayout>
最后我CardView
声明
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/event_row_cardview">
...