android - SlidingDrawer 关闭时显示离底部太远,打开时不与 View 重叠

标签 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)。当我单击它时,它会打开但不会在我的布局上滚动,它仍保留在我在布局中显示的所有内容下方。但我需要,当我点击它时,将它滑过我的 View 。当它关闭时,它应该保持在我的布局下方,离我的布局不太远(比如 150dp)。

抱歉我的英语不好。如果您在理解我所说的内容方面有任何问题,请告诉我。谢谢。

最佳答案

将带有内容的LinearLayoutSlidingDrawer放入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>

关于android - SlidingDrawer 关闭时显示离底部太远,打开时不与 View 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991908/

相关文章:

java - 在其他 View 上方滑动抽屉

java - 启动android模拟器时出现错误!

java - Android - 以编程方式创建一行图标?

android - 如何在一个Android Studio项目中构建两个Android应用程序?

Android SlidingDrawer 位置句柄离屏

java - 没有 fragment 的滑动菜单

android - 如何通过另一个 Activity 中的 Intent 打开 fragment 类?

android - 版本冲突更新到 8.4.0

android - 用户单击 kotlin 中的注销按钮后如何返回登录屏幕?

android - 当 slidingdrawer 打开 listview 参数更改时