0

I am trying to implement simple NavigationDrawer that opens from the right side of the screen. I want to have custom layout instead of ListView/RecyclerView.When I run the app the drawer takes up the entire screen instead of 320dp as I specified? What am I missing here?

<layout xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <include
            android:id="@+id/app_bar"
            layout="@layout/common_app_bar" />

        <com.veriori.veriori.view.VerioriLayout
            android:id="@+id/layer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


        </com.veriori.veriori.view.VerioriLayout>

    </FrameLayout>

    <RelativeLayout
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:gravity="end">

        <ImageView
            android:layout_width="14dp"
            android:layout_height="14dp"
            android:layout_alignParentEnd="true"
            android:layout_margin="21dp"
            android:background="@drawable/ic_cross" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="26dp"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/drawer_item_start"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_start" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_start"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_history"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_history" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_history"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_report"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_report" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_report"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_settings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_settings" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_settings"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <TextView
                android:id="@+id/drawer_manufacturers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="21dp"
                android:text="@string/drawer_manufacturers"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

            <TextView
                android:id="@+id/drawer_about"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="14dp"
                android:text="@string/drawer_veriori"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

            <TextView
                android:id="@+id/drawer_agreements"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="14dp"
                android:text="@string/drawer_agreements"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

        </LinearLayout>
    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33
Booyaches
  • 1,669
  • 4
  • 27
  • 40
  • `DrawerLayout` determines which `View`s are drawers by the `layout_gravity` attribute on them. Your `RelativeLayout` has no `layout_gravity` attribute, so it's treated as a content `View`, and is laid out to fill the `DrawerLayout`. You likely meant for that `android:gravity="end"` to be `android:layout_gravity="end"`. – Mike M. Dec 13 '18 at 18:31

1 Answers1

-1

Instead of

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

replace with this :

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="320dp"
    android:layout_height="match_parent">

and remove 320dp value from your RelativeLayout.

Hope this helps...

Abdul Aziz
  • 442
  • 5
  • 12