Android 中的意外位置出现空视图

Empty view appears in unexpected place in Android

我有这样的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:orientation="horizontal"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/mapbox_fill_white"/>



    </LinearLayout>

    <View
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="100dp">
    </View>


</RelativeLayout>

当我添加下面的视图时,它出现在线性布局上方,但我希望它在布局下方。为什么它在布局之上?我怎样才能解决这个问题?谢谢

您使用的是相对布局,要在线性布局下方显示此视图,您必须为视图分配规则 layout_below,为线性布局提供一个 ID,然后在视图中放置

  android:layout_below="@id/your_linear_layout_id"

使用属性 android:layout_below 将其显示在 LinearLayout 下方,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin" >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:orientation="horizontal" >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="asdf"
            android:background="@color/mapbox_fill_white" />
    </LinearLayout >

    <View
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_below="@+id/linearLayout"
        android:layout_weight="1" >
    </View >
</RelativeLayout >

android:layout_below -- Positions the top edge of this view below the given anchor view ID. Accommodates top margin of this view and bottom margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

检查RelativeLayout LayoutParams