0

我希望当我设置边距底部时,这使得部分视图走出屏幕/不可见,整个布局转移到顶部,看起来“相同” - 意味着,不重新排列内部视图。

但是当我设置边距时,在这个简化的示例中,容器缩小或内部布局移动到底部。这里有图片来说明:

设置边距前:

在此处输入图像描述

设置 200dip 保证金底部后:

在此处输入图像描述

这是 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="400dip"
        android:background="#ff0000"
        android:gravity="center"
        android:layout_marginBottom="200dip"
        >

        <View 
            android:layout_width="fill_parent"
            android:layout_height="200dip"
            android:background="#00ff00"
            />

    </LinearLayout>

    <Button
        android:id="test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />


</RelativeLayout>

我能做些什么来避免这种情况?

4

1 回答 1

0

为此,请尝试在要向上移动的视图顶部设置一个负的上边距。

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="400dip"
        android:background="#ff0000"
        android:gravity="center"
        android:layout_marginTop="-200dip"
        >
于 2012-11-16T19:06:34.823 回答