相对布局约束

Relative layout constraints

我正在尝试创建布局,但不明白如何将一个视图置于另一个视图之下。 这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">

        <TextView
            android:id="@+id/scroll_to_continue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cardview_dark_background"
            android:gravity="center"
            android:text="Scroll to continue with content"
            android:textColor="@color/colorAccent"
            android:textSize="18sp"
            android:typeface="sans" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_above="@id/scroll_to_continue">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/design_default_color_primary"
                android:gravity="center"
                android:text="Tap to Learn More"
                android:textColor="@color/colorAccent"
                android:textSize="18sp"
                android:typeface="sans" />
        </LinearLayout>

    </RelativeLayout>

</FrameLayout>

我想将 LinearLayout 放在 TextView 的正上方,id 为 scroll_to_continue。有人可以帮我吗?

P.S。 android:layout_above="@id/scroll_to_continue" 没有像预期的那样工作 addRule(RelativeLayout.ABOVE, scrollToContinue.getId());

首先,您提供了 TextView 在布局中的位置。我已使用 android:layout_alignParentBottom="true" 将其设置为底部。然后就是工作了。检查以下内容:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">

        <TextView
            android:id="@+id/scroll_to_continue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cardview_dark_background"
            android:gravity="center"
            android:text="Scroll to continue with content"
            android:layout_alignParentBottom="true"
            android:textColor="@color/colorAccent"
            android:textSize="18sp"
            android:typeface="sans" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_above="@id/scroll_to_continue">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/design_default_color_primary"
                android:gravity="center"
                android:text="Tap to Learn More"
                android:textColor="@color/colorAccent"
                android:textSize="18sp"
                android:typeface="sans" />
        </LinearLayout>

    </RelativeLayout>

</FrameLayout>
  <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">

        <TextView
            android:id="@+id/scroll_to_continue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cardview_dark_background"
            android:gravity="center"
            android:text="Scroll to continue with content"
            android:textColor="@color/colorAccent"
            android:layout_below="@+id/linearLayout"
            android:textSize="18sp"
            android:typeface="sans" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:id="@+id/linearLayout">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Tap to Learn More"
                android:textColor="@color/colorAccent"
                android:textSize="18sp"
                android:typeface="sans" />
        </LinearLayout>

    </RelativeLayout>

</FrameLayout>