Is it possible to change the width of NavigationView in Android?

1.2k Views Asked by At

I have a linear layout with list of buttons, sized about 50dp. I was trying to add this layout as the navigation header. I have tried to remove the default list view from the navigation drawer and add my custom layout in the headerLayout (Yea, I am a android noob). But the width of the navigation bar doesn't decrease the width more than half of the full view, even after setting layout_width="wrap_content".
I searched the internet, but there is no info about that. So, is it possible to decrease the width. How do I set my custom layout as the navigation bar?
Edit
Here are the main changes I made:
Nav View Layout

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/custom_nav_bar"/>

custom_nav_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent">
    <include
        layout="@layout/side_bar"
        android:id="@+id/side_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

side_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@color/black"
            android:animateLayoutChanges="true">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_action_home"
                android:id="@+id/homeImgBtn"
                android:background="@color/black"
                android:padding="@dimen/activity_horizontal_margin"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:orientation="horizontal"
                android:id="@+id/homeSelectBar"
                android:background="@color/colorAccent"/>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_action_calender"
                android:id="@+id/calenderImgBtn"
                android:background="@color/black"
                android:padding="@dimen/activity_horizontal_margin"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:orientation="horizontal"
                android:id="@+id/eventSelectBar"
                android:background="@color/colorAccent"/>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_action_controller"
                android:id="@+id/controllerImgBtn"
                android:background="@color/black"
                android:padding="@dimen/activity_horizontal_margin"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:orientation="horizontal"
                android:id="@+id/controllerSelectBar"
                android:background="@color/colorAccent"/>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_action_email"
                android:id="@+id/emailImgBtn"
                android:background="@color/black"
                android:padding="@dimen/activity_horizontal_margin"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:orientation="horizontal"
                android:id="@+id/contactSelectBar"
                android:background="@color/colorAccent"/>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_action_dev"
                android:id="@+id/devImgBtn"
                android:background="@color/black"
                android:padding="@dimen/activity_horizontal_margin"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:orientation="horizontal"
                android:id="@+id/devSelectBar"
                android:background="@color/colorAccent"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
0

There are 0 best solutions below