我有一个根标签为
的活动androidx.constraintlayout.widget.ConstraintLayout
我在这个活动中包含了3个布局文件,并垂直地列出它们。中间一个的以下约束不起作用。
app:layout_constraintTop_toBottomOf="@+id/lay1"
app:layout_constraintBottom_toTopOf="@+id/lay3"
我不明白为什么中间的元素会占据整个屏幕,而不是从顶部元素的底部开始到底部元素的顶部结束。你能帮我解决这个问题吗?
这个活动:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/lay1"
layout="@layout/empty_linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/lay2"
layout="@layout/empty_linear_layout"
app:layout_constraintBottom_toTopOf="@+id/lay3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lay1" />
<include
android:id="@+id/lay3"
layout="@layout/empty_linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
空的线性布局文件:empty_linear_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="button" />
</LinearLayout>