recyclerview 中的 cardviews 之间的差距太大
too much gap between cardviews in a recyclerview
我在 RelativeLayout 中有一个 RecyclerView,如下所示:
<android.support.v7.widget.RecyclerView
android:id="@+id/cards_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:background="#eeff99"/>
我在 LinearLayout 中有卡片视图,如下所示:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/quote_card"
android:layout_height="200dp"
android:layout_width="match_parent"
card_view:cardBackgroundColor="#666"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
app:cardUseCompatPadding="true"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/display_author_name"
android:text="Author Name"
android:textSize="18sp"
android:textColor="#333"
android:gravity="center_horizontal"/>
</android.support.v7.widget.CardView>
卡片之间的差距很大。滚动一点后才能看到下一张卡片。我错过了什么?
滚动前的图片:
滚动后:
试试这个:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/quote_card"
android:layout_height="200dp"
android:layout_width="match_parent"
card_view:cardBackgroundColor="#666"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
app:cardUseCompatPadding="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/display_author_name"
android:text="Author Name"
android:textSize="18sp"
android:textColor="#333"
android:gravity="center_horizontal"/>
</android.support.v7.widget.CardView>
</LinearLayout>
将卡片视图放在线性布局中,并使用填充来改变间隙
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
*android:padding="1dp"*
>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
style="@style/list_card"
android:layout_width="match_parent"
android:layout_height="90dp" >
在您的 LinearLayout
中进行这些更改。如果 layout_height
是 match_parent
,它会占用屏幕 space
android:layout_width="match_parent"
android:layout_height="wrap_content"
您将卡片视图高度用作匹配父项,因此如果父项高度也与父项匹配而不是将父项高度更改为包装内容,如果您仅将卡片视图用作父项而不是更改其高度以包装内容..可能会有所帮助你
我在 RelativeLayout 中有一个 RecyclerView,如下所示:
<android.support.v7.widget.RecyclerView
android:id="@+id/cards_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:background="#eeff99"/>
我在 LinearLayout 中有卡片视图,如下所示:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/quote_card"
android:layout_height="200dp"
android:layout_width="match_parent"
card_view:cardBackgroundColor="#666"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
app:cardUseCompatPadding="true"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/display_author_name"
android:text="Author Name"
android:textSize="18sp"
android:textColor="#333"
android:gravity="center_horizontal"/>
</android.support.v7.widget.CardView>
卡片之间的差距很大。滚动一点后才能看到下一张卡片。我错过了什么?
滚动前的图片:
滚动后:
试试这个:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/quote_card"
android:layout_height="200dp"
android:layout_width="match_parent"
card_view:cardBackgroundColor="#666"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
app:cardUseCompatPadding="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/display_author_name"
android:text="Author Name"
android:textSize="18sp"
android:textColor="#333"
android:gravity="center_horizontal"/>
</android.support.v7.widget.CardView>
</LinearLayout>
将卡片视图放在线性布局中,并使用填充来改变间隙
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
*android:padding="1dp"*
>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
style="@style/list_card"
android:layout_width="match_parent"
android:layout_height="90dp" >
在您的 LinearLayout
中进行这些更改。如果 layout_height
是 match_parent
,它会占用屏幕 space
android:layout_width="match_parent"
android:layout_height="wrap_content"
您将卡片视图高度用作匹配父项,因此如果父项高度也与父项匹配而不是将父项高度更改为包装内容,如果您仅将卡片视图用作父项而不是更改其高度以包装内容..可能会有所帮助你