Android 相互重叠的线性布局

Android linear layout on top of each other

我在 Android Studio 工作,试图按照我想要的方式布置 Activity。对我来说不幸的是,我的布局是一个叠一个,而不是一个在另一个下面。

这就是我想要的:

现在,我在约束布局中添加了两个线性布局。

我希望第二个线性布局紧挨着第一个线性布局的下方,因为第一个布局的 ID 是“layout_general_settings”并且我已指示第二个布局从底部开始第一个布局

app:layout_constraintTop_toBottomOf="layout_general_settings"

但是,两个线性布局都位于 activity 的顶部 – 即它们彼此重叠/位于同一位置。

谁能告诉我我做错了什么?

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SettingsActivity"
    >


    <LinearLayout
        android:id="@+id/layout_general_settings"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        >

        <TextView
        :
        />
        <TextView
        :
        />


    </LinearLayout>


    <LinearLayout
        android:id="@+id/layout_temperature_settings"
        app:layout_constraintTop_toBottomOf="layout_general_settings"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        >

        <TextView
        :
        />
        <TextView
        :
        />

    </LinearLayout>

谢谢

加勒特

您缺少“@+id/” 在你的行中:

app:layout_constraintTop_toBottomOf="layout_general_settings

这是必须的;

app:layout_constraintTop_toBottomOf="@+id/layout_general_settings