Search code examples
androidandroid-layoutandroid-listviewandroid-activityslidingdrawer

ListView on top of the drawer ListView


I am trying to have 2 listview in the same main activity. One list view for my horizontal drawer (sliding from the left), and the other list view on the center. It will show the drawer list view when I click on the drawer, but the drawer view didn't slide over the center list view instead the center is on top of it, so I can't actually see anything from the drawer. I am wondering if there's something wrong with my main_activity.xml that my res/layout directory (I am actually not sure if it's the right way for doing it as putting two list views in one activity)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                tools:context=".MainActivity" >

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

                 <ListView android:id="@+id/drawer"
                           android:layout_width="240dp"
                           android:layout_height="match_parent"
                           android:layout_gravity="start"
                           android:choiceMode="singleChoice"
                           android:divider="@android:color/transparent"
                           android:dividerHeight="0dp"
                           android:background="#111"/>

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

            <ListView android:id="@+id/deviceList"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:divider="#b5b5b5"
                      android:dividerHeight="1dp"
                      android:listSelector="@drawable/list_selector" />

</RelativeLayout>   

Solution

  • I think you can simply reorder it by having the ListView (wrapped it with LinearLayout) before the DrawerLayout like this

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ListView
            android:id="@+id/deviceList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp"
            android:drawSelectorOnTop="false"
            android:listSelector="@drawable/device_list_item_selector"
            android:scrollbarStyle="outsideOverlay" />
    </LinearLayout>
    
    <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="fill_parent" >
    
        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#111"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp" />
    </android.support.v4.widget.DrawerLayout>
    

    and make sure you have fill_parent for layout_height for both