Ron Ron - 1 month ago 6
Android Question

too much gap between cardviews in a recyclerview

i have a recyclerview inside a relativeLayout like so:

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


and i have card view within a LinearLayout like so:

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


the gap between the cards are huge. the next card is seen only after one scroll a bit. what am i missing?

before scrolling

after scrolling

Answer

Try this

 <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>
Comments