0

I have navigation drawer. In which i have one header and other is items list. Now the problem is how to add three items in a same row.Like

 Header xyz

    --------------------------
        Image   Text     Text    -----> row one
   ----------------------------- 
        iamge   text     text    ------> row two
    ----------------------------
        image   text     text    ------> row three
    ---------------------------
----- ....... so on

And when user click on the any item of the list that item should display on the header. Please guide me.

Gyan S Awasthi
  • 237
  • 6
  • 14

2 Answers2

0

You should create your custom navigation drawer then you can achieve your requirement. for more follow this tutorial http://www.tutecentral.com/android-custom-navigation-drawer/

May this help you.

Gau
  • 141
  • 2
  • 7
0

1.Use NavigationView

2.Add layout to NavigationView

3.add RecyclerView to layout (and set GridLayoutManager)

The important is use inflateHeaderView method in your code .

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true">

<FrameLayout
    android:id="@+id/frame_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="@dimen/dp_200"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/white"
    android:paddingTop="@dimen/dp_25"/>
</android.support.v4.widget.DrawerLayout>

header_layout

<?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:fitsSystemWindows="true"
          android:orientation="vertical">

<TextView
    android:id="@+id/tv_header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

</LinearLayout>

activity

View headview = mNavigationView.inflateHeaderView(R.layout.header_layout);
TextView tvHeader = (TextView) headview.findViewById(R.id.tv_header);
RecyclerView recyclerView = (RecyclerView) headview.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this,3));
recyclerView.setAdapter(mAdapter);
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42