Thursday, February 17, 2011

SlidingDrawer

By Magesh Kumar   Posted at  2:36 AM   Android No comments


Unlike most other Android containers, SlidingDrawer moves, switching from a closed to an open position. This puts some restrictions on which container holds the SlidingDrawer. It needs to be in a container that allows multiple widgets to sit atop each other. RelativeLayout and FrameLayout satisfy this requirement; FrameLayout is a container purely for stacking widgets atop one another. On the flip side, LinearLayout does not allow widgets to stack (they fall one after another in a row or column), and so we should not have a SlidingDrawer as an immediate child of a LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#FF4444CC"
              >
       <SlidingDrawer
              android:id="@+id/drawer"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:handle="@+id/handle"
              android:content="@+id/content">
              <ImageView
                    android:id="@id/handle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tray_handle_normal"
              />
              <Button
                    android:id="@id/content"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="I'm a SlidingDrawer!"
              />
       </SlidingDrawer>
</FrameLayout>
The SlidingDrawer should contain two things:
  • A handle, frequently an ImageView or something along those lines, such as the one used here, pulled from the Android open source project.
  • The contents of the drawer itself, usually some sort of container, but a Button in this case.





About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.