See navigation drawer preview

TomCB picture TomCB · Mar 31, 2015 · Viewed 8.5k times · Source

I'm designing a native navigation drawer in Android Studio. I can't see the drawer in my preview because it is sitting left of the activity, out of range of the preview. For now I'm using a testlayout.xml file to see my changes, but a lot of times I forget to copy paste them into the right activity. Is there a way to preview the drawer layout?

Answer

Yoker picture Yoker · Jun 30, 2015

If you want to be able to preview the drawer layout / navigation bar

If you are following the tutorial at https://developer.android.com/training/implementing-navigation/nav-drawer.html

You can put your listview for the nav drawer in a different xml file in the /layout folder, then include it in the drawer layout xml. Means you can edit it in the drawer_layout file and be able to see it properly

layout/drawer_layout

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/left_drawer"
      android:layout_width="280dp"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:choiceMode="singleChoice"
      android:divider="@android:color/transparent"
      android:dividerHeight="0dp"
      android:background="@color/nav_drawer_background_color"/>

Then in the navbar

<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">


</FrameLayout>

<!-- The navigation drawer -->
<include
    android:id="@+id/listView"
    layout="@layout/drawer_layout"/>
</android.support.v4.widget.DrawerLayout>