Android 如何通过XML设置滑动抽屉的高度?

Android 如何通过XML设置滑动抽屉的高度?,android,android-layout,Android,Android Layout,我正在尝试使用一个从下到上结构的滑动抽屉。。我在滑动抽屉里放了4个旋转器。。当我执行时,句柄(我有一个图像)显示在屏幕上方。我希望把手刚好在内容上方(即刚好在4个微调器上方) 这是我的xml布局 main.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wid

我正在尝试使用一个从下到上结构的滑动抽屉。。我在滑动抽屉里放了4个旋转器。。当我执行时,句柄(我有一个图像)显示在屏幕上方。我希望把手刚好在内容上方(即刚好在4个微调器上方)

这是我的xml布局

main.xml

<?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:orientation="vertical">
    <SlidingDrawer
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/drawer"
        android:handle="@+id/MyHandle"
        android:content="@+id/MyContent">
            <LinearLayout 
                android:id="@+id/MyHandle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="bottom"
                android:orientation="vertical">
                <ImageView 
                    android:id="@+id/SlideIcon"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:src="@drawable/images"/>
            </LinearLayout>
            <FrameLayout 
                android:id="@+id/MyContent"
                android:layout_width="fill_parent"
                android:layout_height="200dip"
                android:orientation="vertical">
                <include
                    android:id="@+id/DrawerContent"
                    layout="@layout/spinnerlayout" 
                    android:layout_height="wrap_content"/>
            </FrameLayout>
    </SlidingDrawer>
</FrameLayout>

和spinnerlayout.xml

<?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="wrap_content"
    android:foregroundGravity="bottom"
    android:layout_gravity="bottom"
    android:background="@color/grey">

    <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical">
        <Spinner 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_first"/>
        <Spinner 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_second"/>
        <Spinner 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_third"/>
        <Spinner 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_fourth"/>
    </LinearLayout>
</FrameLayout>

为了让我的问题更清楚,我有截图

我想把那个把手(箭头)放在旋转器的正上方

可以放置它吗?

SlidingDrawer类的onMeasure()方法基本上会覆盖布局模式以填充父级,这就是为什么布局\u height=“wrap\u content”不起作用的原因

为了解决这个问题,您可以使用重新实现的onMeasure()方法扩展SlidingDrawer,该方法支持layout_width和layout_height属性。然后,可以在XML布局中使用此自定义类,方法是替换为

请注意,由于抽屉将不再填充父布局,因此必须将其封闭在线性布局中,并将重力属性设置为抽屉应位于的边缘

答案是

SlidingDrawer类的onMeasure()方法基本上覆盖了布局模式以填充父级,这就是为什么layout\u height=“wrap\u content”不起作用的原因

为了解决这个问题,您可以使用重新实现的onMeasure()方法扩展SlidingDrawer,该方法支持layout_width和layout_height属性。然后,可以在XML布局中使用此自定义类,方法是替换为

请注意,由于抽屉将不再填充父布局,因此必须将其封闭在线性布局中,并将重力属性设置为抽屉应位于的边缘

答案是

我知道,亲爱的,通过覆盖onMeasure()我可以设置它。。还有很多例子。但我问这个问题是想知道是否有可能设置高度。。您的意见是什么,先生,可能吗?这是您的另一个示例我知道亲爱的,通过覆盖onMeasure()我可以设置它。。还有很多例子。但我问这个问题是想知道是否有可能设置高度。。先生,您的意见是什么?这是另一个给您的样品