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">
...