0

Good morning. I have a layout like this:

<android.support.v4.widget.DrawerLayout

  <android.support.design.widget.CoordinatorLayout
    ...
  </android.support.design.widget.CoordinatorLayout>

  <android.support.design.widget.NavigationView
    android:id="@+id/main_drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:itemTextColor="@color/jet"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/action_menu" />

  <ListView
      android:id="@+id/navList"
      android:layout_width="200dp"
      android:layout_height="match_parent"
      android:layout_gravity="left|start"
      android:background="@color/chalk" />

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

And then, on my Activity I populate the ListView like this:

String[] osArray = {"CERRAR SESIÓN", "ACERCA DE"};
    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
    listView.setAdapter(arrayAdapter);

My issue is that the layout I'm using as a header for the drawer, overlaps the ListView. I have tried also giving the ListView a marginTop, but although that works in Android Studio (apparently), it solves nothing when running the code.

Just in case, here is the layout I use as a header for the drawer:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/header_height"
    android:background="@color/accent"
    android:gravity="bottom"
    android:orientation="vertical"
    android:padding="@dimen/header_left_padding"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

<TextView
    android:id="@+id/username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/user_name"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
    android:textStyle="bold" />

<TextView
    android:id="@+id/email"
    style="@style/Widget.AppCompat.Spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/user_email"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

</LinearLayout>

Any help will be appreciated, thank you.

2 Answers2

0

You can try using

Theme.Appcompat

Instead of theme overlay for the linear layout

Ameya Kulkarni
  • 198
  • 1
  • 2
  • 14
  • Thank you, but that didn't change a thing. –  Dec 27 '15 at 16:05
  • Please view this question http://stackoverflow.com/questions/30978114/add-a-listview-or-recyclerview-to-new-navigationview you might find some valuable information here – Ameya Kulkarni Dec 27 '15 at 16:19
  • Thanks. It will help me for a future update on the code. –  Dec 27 '15 at 16:28
0

I think you misunderstand the NavigationView and the older design pattern for DrawerLayout. In older days we have to use listView to populate the drawer menu but with creation of NavigationView we now put what we want into the xml files. so your layout should be:

<android.support.v4.widget.DrawerLayout

  <android.support.design.widget.CoordinatorLayout
    ...
  </android.support.design.widget.CoordinatorLayout>

  <android.support.design.widget.NavigationView
    android:id="@+id/main_drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:itemTextColor="@color/jet"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/action_menu" />



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

and you must populate your drawer menu by these two xml files

app:headerLayout="@layout/drawer_header"
app:menu="@menu/action_menu"

you can use @layout/drawer_header to design the header menu and action_menu to create your list items of the drawer menu.