-5

Please suggest how to create this type of layout in recycleview with full height.

Please suggest how to create this type of layout in recycleview with full height.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163

1 Answers1

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:

enter image description here

I hope its work for you.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Android Geek
  • 8,956
  • 2
  • 21
  • 35