I want the items in the RecycledView to be wrapped if there is enough space on the screen, much like how the Google Play Store is designed. How can I achieve this?
Recycled View:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:weightSum="1">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.9">
<android.support.v7.widget.RecyclerView
android:id="@+id/dashboard_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
</LinearLayout>
Items:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:clickable="true" >
<ImageView
android:id="@+id/sensor_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/sensor_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sensor_image" />
</LinearLayout>
</android.support.v7.widget.CardView>
OnCreateView():
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.Inflate(Resource.Layout.Dashboard, container, false);
recyclerView = view.FindViewById<RecyclerView>(Resource.Id.dashboard_recycler_view);
layoutManager = new GridLayoutManager(Activity, 2);
recyclerView.HasFixedSize = true;
recyclerView.SetLayoutManager(layoutManager);
recyclerView.SetItemAnimator(new DefaultItemAnimator());
recyclerView.AddItemDecoration(new SpaceItemDecoration(20));
return view;
}
How it looks so far:
As you can see, the items don't wrap, they just shrink so they can fit in the view.