Wednesday, March 30, 2011

SlidingDrawer

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="300dip"
android:layout_gravity="bottom"
android:background="#808080">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Something here: \nIt's a exercise \nof SlidingDrawer"
/>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:background="#404040"/>
<LinearLayout
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:orientation="vertical"
android:background="#606060"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's content of SlidingDrawer"/>
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dip"
android:text=" - A Bit Button - "/>
</LinearLayout>



Related:
- SlidingDrawer in horizontal
- Inflate SlidingDrawer from XML



2 comments:

'V' for Veena said...

Do you have the Java file for this implementation? If you do, could you please post it? It would be of great help. Thank you very much!

Erik said...

hello Veena,

No Java code needed, it can be implement in XML.

Or, you want implement in Java, instead of XML?