Learner Learner - 4 months ago 39
Android Question

Making more thatn one card view to be visible in horizontal recyclerview

Im trying to create horizontally swipeable recyclerview that contains multiple carview items. Following is the way How Im setting the adapter

LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
horizontal_recycler_view.setLayoutManager(horizontalLayoutManagaer);
horizontal_recycler_view.setItemAnimator(new DefaultItemAnimator());
horizontal_recycler_view.setAdapter(adapter);


Following is my recyclerview item code layout code.

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">

<ImageView
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="@dimen/album_cover_height"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY" />

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:paddingTop="@dimen/album_title_padding"
android:textColor="@color/album_title"
android:textSize="@dimen/album_title" />

<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:paddingBottom="@dimen/songs_count_padding_bottom"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:textSize="@dimen/songs_count" />

<ImageView
android:id="@+id/overflow"
android:layout_width="@dimen/ic_album_overflow_width"
android:layout_height="@dimen/ic_album_overflow_height"
android:layout_alignParentRight="true"
android:layout_below="@id/thumbnail"
android:layout_marginTop="@dimen/ic_album_overflow_margin_top"
android:scaleType="centerCrop"
android:src="@drawable/ic_dots"
/>

</RelativeLayout>

</android.support.v7.widget.CardView>


The problem is that only one card is visible at a time but I want more than one card to be visible as in google play . How can I be able to sort this out?

A

As you can see the layout contains both horizontal recycler view. Then it contains vertical recycler view. The horizontal recycler view shows only one cardview and show the other views when it is swipes but i want to show multiple views at the same time.

sJy sJy
Answer

Try

  1. Set your parent LinearLayout as well as child views width as wrap_content.
  2. ImageView with id overflow is aligned to right of the parent. Remove that and add android:layout_alignRight="@id/thumbnail"