0

在以下布局中使用它时,我无法让我的相对布局视图缩小,用作对话框。在下面的示例中,滚动视图总是扩展以填充整个对话框,如果实际内容不多,这看起来很丑陋。

我尝试了大多数 fill_parent、wrap_content 等组合,但均未成功。

问题似乎是将按钮设置为“align_bottom”会导致对话框填充其高度。但是,如果我更改顺序并且必须将按钮放在滚动视图下方,那么如果显示了很多内容,则该按钮将不可见......

解决方法(我认为这是一个非常丑陋的解决方案)是在滚动视图上设置一个边距底部,然后在按钮上设置相同的负边距顶部。但我不确定这将如何看待不同的显示器。

请帮助/Rudas

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/dialogCloseButton"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:id="@+id/dialogContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="10dp" >

            <TextView
                android:id="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TextView>
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/dialogCloseButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Close" >
    </Button>

</RelativeLayout><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/dialogCloseButton"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:id="@+id/dialogContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="10dp" >

            <TextView
                android:id="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TextView>
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/dialogCloseButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Close" >
    </Button>

</RelativeLayout>
4

1 回答 1

0

ScrollView 是 FrameLayout 的特殊类型。这意味着它将始终从父布局的左上角开始。效果与其他视图重叠,RelativeLayout 设置将不起作用。解决方案是将 StrollView 放在单独的布局中(例如 LinearLayout)。

于 2010-08-03T08:49:55.193 回答