【发布时间】:2021-06-17 01:42:39
【问题描述】:
我有两个 TextViews 和一个 ScrollView 嵌套在 ConstraintLayout 中。在ScrollView 里面有一个TableLayout。 ScrollView 的左、右和下约束设置为“父”。顶部约束设置为它之前的 TextView。这是 XML:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:gravity="center"
android:stretchColumns="0,1,2,3,4">
<TableRow
android:layout_width="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1" />
... 4 more TextViews
</TableRow>
... many more TableRows
</TableLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
问题是 ScrollView 的宽度与其约束不匹配。相反,当添加更多行以使 ScrollView 高于其父级的剩余高度时,它会与之前的 TextView 重叠。下面的两张截图说明了这个问题:
无重叠:
重叠:
当我将 ScrollView 高度设置为“0dp”(匹配约束)时,它按字面意思呈现为 0dp(ScrollView 缩小并且不显示任何内容)。
我应该改变什么以使 ScrollView 展开并填充其父容器的剩余高度?
【问题讨论】:
标签: android scrollview android-constraintlayout