SlidingDrawer移动到原始屏幕上

时间:2012-01-25 21:16:13

标签: android android-layout slidingdrawer

我的应用程序包含一个包含horizental SlidingDrawer的屏幕。 当用户按下抽屉把手时,抽屉应“覆盖”整个屏幕。当它关闭时,“原始”屏幕应该显示出来。 我已将抽屉放在FrameLayout中,但手柄消失了。

如何解决?

谢谢, 的Eyal

1 个答案:

答案 0 :(得分:3)

好笑,我刚刚解决了这个问题。我花了一点时间,但经过一些谷歌搜索和测试,我想出了这个:

基本上我把整个布局放到“相对布局”中,然后在主要内容中创建一个“线性布局”。在“相对布局”内部但在“线性布局”之外我放了“SlidingDrawer”。我在下面的xml中显示按钮和句柄。另外,我在“SlidingDrawer”中为内容创建了“线性布局”。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

 ..stuff for the main screen

</LinearLayout>
<SlidingDrawer
    android:id="@+id/SlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:content="@+id/contentLayout"
    android:handle="@+id/slideHandleButton" >
    <Button
        android:id="@+id/slideHandleButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/list_background"
        android:padding="8dp"
        android:text="My App"
        android:textSize="7pt" >
    </Button>
    <LinearLayout>

        ...sliding drawing is at the bottom
    ...stuff in here will be in the sliding drawer

    </LinearLayout>
</SlidingDrawer>
</RelativeLayout>

在发布之前,我只是使用此代码运行我的测试应用程序,它可以工作。如果您有任何疑问,请询问,我希望这会有所帮助。

enter image description here