我所拥有的:
我有4个小部件,放置在约束布局内,其父级是滚动视图
我想做什么:
我正在尝试将小部件一个显示在另一个下方
发生了什么:
小部件一个接一个地放置
MyLayout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edtNameId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/str_name"
android:inputType="text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<EditText
android:id="@+id/edtPwdId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/str_password"
app:layout_constraintBottom_toBottomOf="@+id/edtNameId"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<TextView
android:id="@+id/txtChangePwdId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/str_change_password"
app:layout_constraintBottom_toBottomOf="@+id/edtPwdId"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<Button
android:id="@+id/btnSubmitId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/str_submit"
app:layout_constraintBottom_toBottomOf="@+id/txtChangePwdId"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
输出:
您应该使用layout_constraintTop_toBottomOf
而不是app:layout_constraintBottom_toBottomOf
试试这个