how can i add an image header to my navigation drawer layout like this one
In the Navigation Drawer layout xml file. Above drawerView and inside your parent layout add an image view as shown below:
<ImageView
android:id="@+id/image"
android:layout_width="280dp"
android:layout_height="140dp"
android:src="respective_source_of_image" />
This should be sufficient. Hope this helps.
Use Recycler View to create a navigation drawer. Recycler view is used most now. In your navigation drawer fragment have your layout file as shown below. This make you achieve your objective:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ms.t.tms.NavigationDrawerFragment">
<ImageView
android:id="@+id/image"
android:layout_width="280dp"
android:layout_height="140dp"
android:src="respective_image_src" />
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/image"
android:background="@color/colorPrimary"></android.support.v7.widget.RecyclerView>
</RelativeLayout>
You can simply do it following this sample :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- insert you main view childs here -->
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:layout_width="240dp"
android:layout_gravity="end"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="240dp"
android:layout_height="140dp"
android:src="@drawable/logo" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:background="@color/colorPrimary"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
You will have your image added before the listview. You can manage your view like any other view.
Hope it will help you ;)