Please suggest how to create this type of layout in recycleview with full height.
Asked
Active
Viewed 65 times
-5
-
`RecyclerView` with `GridLayoutManager` .. Try it yourself first .. – ADM May 23 '19 at 07:19
-
Just set for `RecyclerView` `new GridLayoutManager(this, 2);` – Dmitriy Mitiai May 23 '19 at 07:20
-
And also you need to use [SquareLayout](https://stackoverflow.com/questions/16748124/custom-square-linearlayout-how) – Nick Bapu May 23 '19 at 07:20
-
https://stackoverflow.com/q/40587168/7666442 – AskNilesh May 23 '19 at 07:20
-
Possible duplicate of [Simple Android grid example using RecyclerView with GridLayoutManager (like the old GridView)](https://stackoverflow.com/questions/40587168/simple-android-grid-example-using-recyclerview-with-gridlayoutmanager-like-the) – MrMaavin May 23 '19 at 07:23
-
you have to mention what exactly is a problem for you to create it. – Vladyslav Matviienko May 23 '19 at 07:24
1 Answers
0
Please try below code:
actvity_layout.xml
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:gravity="center"
android:background="@color/colorBlueBg">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlueBg"/>
</LinearLayout>
layout for item
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:id="@+id/linear_item_submenu"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/colorBlue"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="50dp">
<ImageView
android:id="@+id/item_main_submenu_img"
android:layout_width="50dp"
android:layout_height="50dp"/>
<View android:layout_width="20dp"
android:layout_height="1dp"
android:background="#EBCD08"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="@+id/item_main_submenu_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1111"
android:gravity="center"
android:textSize="13sp"
android:textColor="@color/colorWhite"
android:padding="5dp"
android:textAllCaps="true"/>
</LinearLayout>
</android.support.v7.widget.CardView>
In java file
recyclerview = findViewById(R.id.recyclerview);
recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, 1));
final RecyclerModel[] homeOptionsModel=new RecyclerModel[]{
new RecyclerModel(R.drawable.ic_android,"FLIGHTS"),
new RecyclerModel(R.drawable.ic_android,"Hotels"),
new RecyclerModel(R.drawable.ic_android,"Holodays"),
new RecyclerModel(R.drawable.ic_android,"deals"),
};
recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, 1));
RecyclerViewAdapter recyclerViewAdapter=new RecyclerViewAdapter(MainActivity.this, homeOptionsModel);
recyclerview.setAdapter(recyclerViewAdapter);
Output for code:
I hope its work for you.

piet.t
- 11,718
- 21
- 43
- 52

Android Geek
- 8,956
- 2
- 21
- 35