Reputation: 1051
I want to create a RecyclerView with two CardViews visible inside of it that can scroll horizontally. Similar to the picture below.
Setting the LayoutManager to this code creates the desired format but it is scrolling vertically.
recyclerView.SetLayoutManager(new GridLayoutManager(Context, 2, GridLayoutManager.Vertical, false));
Setting the LayoutManager to this code creates an incorrect format but it is scrolling horizontally.
recyclerView.SetLayoutManager(new GridLayoutManager(Context, 2, GridLayoutManager.Horizontal, false));
My question is how do I create a format of two CardViews that are side by side and can scroll horizontally?
Here is the CardView XML just in case it is needed:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/cardView"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000">
</RelativeLayout>
</android.support.v7.widget.CardView>
Upvotes: 0
Views: 359
Reputation: 8254
Try using a LinearLayoutManager with horizontal orientation:
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
If you want to show 2 cards at the same time, set their width to half of the screen size.
Upvotes: 1