SlidingDrawer在关闭时显示距离底部太远,并且在打开时不会与视图重叠

时间:2012-12-21 14:26:42

标签: android slidingdrawer

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
    android:layout_height="fill_parent"
        android:background="#FFF">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center">

        .................................
        .................................

        <SlidingDrawer
        android:layout_width="fill_parent"
        android:id="@+id/SlidingDrawer"
        android:handle="@+id/slideButton"
        android:content="@+id/contentLayout"
        android:padding="10dp"
        android:layout_height="150dp">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/slideButton"
                android:background="@drawable/action_eating">
            </Button>
            <LinearLayout
                android:layout_width="fill_parent"
                android:id="@+id/contentLayout"
                android:orientation="vertical"
                android:gravity="center"
                android:padding="10dp"
                android:background="#45454F"
                android:layout_height="wrap_content">
            <Button
            android:id="@+id/history"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/history"
            android:textColor="#000000"
            android:textSize="20sp" />
        </LinearLayout>
    </SlidingDrawer>

    </LinearLayout>    

</ScrollView>

问题是,SlidingDrawer保留在我的布局底部(没关系),但它在底部仍然太远(我认为它在我的布局下仍然是150dp)。当我点击它时,它会打开,但不会在我的布局上滚动,它仍然保留在我在布局中显示的所有内容之下。但我需要,当我点击它时,将它滑过我的视图。当它关闭时,它应该保持在我的布局下方,与我的布局相差不远(如150dp)。

抱歉我的英语不好。如果您有任何问题需要了解我所说的内容,请告诉我。谢谢。

2 个答案:

答案 0 :(得分:1)

将您的LinearLayout内容和SlidingDrawer放入RelativeLayout

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFF">
<RelativeLayout
android:layout_width="fill_parent"
        android:layout_height="fill_parent">

<LinearLayout
android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center">

        // your content
</LinearLayout>

<SlidingDrawer
android:layout_width="fill_parent"
        android:id="@+id/SlidingDrawer"
        android:handle="@+id/slideButton"
        android:content="@+id/contentLayout"
        android:padding="10dp"
        android:layout_height="150dp">

<Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/slideButton"
        android:background="@drawable/action_eating">
</Button>
<LinearLayout
android:layout_width="fill_parent"
        android:id="@+id/contentLayout"
        android:orientation="vertical"
        android:gravity="center"
        android:padding="10dp"
        android:background="#45454F"
        android:layout_height="wrap_content">
<Button
android:id="@+id/history"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/history"
        android:textColor="#000000"
        android:textSize="20sp" />
</LinearLayout>
</SlidingDrawer>

</RelativeLayout>

</ScrollView>

答案 1 :(得分:0)

我找到了它。这就是我所做的:

首先,我使用<RelativeLayout>作为父母。在这个父母下我使用了<ScrollView>。然后我从<SlidingDrawer>中删除<ScrollView>并将其粘贴到<ScrollView>下但<RelativeLayout>下。但在那之后,当我点击抽屉按钮时,它打开但覆盖了我不想要的整个屏幕。我只想要wrap_content。所以我用过:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="#FFF"
    android:gravity="bottom"
    android:layout_gravity="bottom">
<SrollView .....>
    .............................
    .............................
</ScrollView>

<SlidingDrawer
    android:layout_width="wrap_content"
    android:id="@+id/SlidingDrawer"
    android:handle="@+id/slideButton"
    android:content="@+id/contentLayout"
    android:layout_height="95dp"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">

    ..................
    ..................

</SlidingDrawer>
</RelativeLayout>