2010-11-01 84 views
2

我看了很多地方,但我找不到一个像样的教程,如何为我的应用程序制作一个SlidingDrawer。Android SlidingDrawer how-to

说我已经有一个XML文件,我想添加一个滑动抽屉给它..我也想添加一个textview和listview对象,并在它的一些按钮...我会怎么做?

任何帮助将不胜感激!

回答

3

这是SlidingDrawer sample app。特别是,这里的布局:

<?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 in here!" 
     /> 
    </SlidingDrawer> 
</FrameLayout> 

现在,在这种情况下,整个活动仅仅是一个SlidingDrawer。这是相当不寻常的 - 这个例子很简短,因为它来自一本书。

更常见的情况是,我希望您将作为RelativeLayout的孩子,因此您可以让RelativeLayout的其他孩子在打开时将其抽屉滑过顶部。我相信在这种情况下,您需要SlidingDrawer成为RelativeLayout的最后一个孩子。

+0

非常感谢!我会给这个镜头。 – somanys21 2010-11-01 20:42:42