2016-03-02 110 views
0

我目前使用RecyclerView来显示卡片列表。 它与ListViewArrayListAdapter很好,但现在发生了一些奇怪的事情。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"> 
    ... 

回答

0

我发现的来源问题。

我的CardView被包裹在一个LinearLayout的属性android:layout_height="match_parent"中,所以每次渲染时都会占用屏幕的整个高度。

我修改了它的属性为android:layout_height="wrap_content"