androidlistviewslidingdrawer

Add a ListView Into a SlidingDrawer?


How do I inflate a ListView into a SlidingDrawer? Thnx for the input.

The main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<WebView android:id="@+id/webView1" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</WebView>

<include android:id="@+id/windowTitle" layout="@layout/window_title" />
<include android:id="@+id/slidingDrawer" layout="@layout/sliding_drawer" />

</FrameLayout>

The Drawer XML:

<SlidingDrawer android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer" android:handle="@+id/handle" android:content="@+id/content"
android:allowSingleTap="false">

<LinearLayout android:id="@+id/handle"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="20dip" android:background="@drawable/gradient2">

    <ImageView android:id="@+id/handleGrip" android:src="@drawable/handle"
        android:layout_height="wrap_content" android:gravity="center"
        android:layout_centerInParent="true" android:layout_gravity="center"
        android:layout_width="match_parent" />

</LinearLayout>

<ListView android:id="@+id/content" android:layout_height="match_parent"
    android:background="#000" android:layout_width="wrap_content" />

</SlidingDrawer>

Solution

  • You have to do something like this.

    <SlidingDrawer android:id="@+id/drawer" android:handle="@+id/handle"
        android:content="@+id/content" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:orientation="vertical"
        android:layout_gravity="bottom">
    
        <LinearLayout android:id="@id/content"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:orientation="vertical">
    
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:text="Below there is a list view." />
    
            <ListView android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:id="@+id/listview_"
                android:divider="@android:color/transparent" 
                android:dividerHeight="10.0sp" />
    
        </LinearLayout>
    
        <ImageView android:id="@id/handle" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:background="@drawable/icon" />
    
    </SlidingDrawer>