I am working in Android Studio, trying to layout an Activity the way I want. Unfortunately for me, my layouts are sitting on top of each other, instead of one being below the other.
This is what I want:
View groups aligned vertically, one after the other, all aligned to the left
Within each view group I have various text views etc.
Right now, I have added two Linear Layouts within a Constraint Layout.
I would expect the second Linear Layout to be immediately BELOW the first Linear Layout, because the ID fo the first layout is "layout_general_settings" and I have instructed the second layout to start at the bottom of the first layout
app:layout_constraintTop_toBottomOf="layout_general_settings"
However, both linear layouts are at the top of the activity – i.e. they are on top of each other / they are in the same location.
Can anyone tell me what I am doing wrong?
<?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>
Thanks
Garrett
CodePudding user response:
You missing "@ id/" In your line:
app:layout_constraintTop_toBottomOf="layout_general_settings
It's need to be;
app:layout_constraintTop_toBottomOf="@ id/layout_general_settings