Question

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>   
Was it helpful?

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

OTHER TIPS

Try This:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->

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

        <!--
         As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions.
        -->

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <RelativeLayout
            android:id="@+id/relative1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ListView
                android:id="@+id/lst_week"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:dividerHeight="1dp" >
            </ListView>
        </RelativeLayout>

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

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:dividerHeight="0.5dp" />
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top