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);