【发布时间】:2019-10-15 15:01:19
【问题描述】:
我有以下布局。注意Z 位于Y 下方,但被限制在底部。 Y 和 Z 之间有一个很好的间隙,这是由多余的垂直空间提供的。这是我的期望和实际在存在多余的垂直空间时的行为。
但是,当显示键盘时,我用完了多余的垂直空间。
期望的行为(没有多余的垂直空间)当我用完垂直空间时,我希望发生以下情况:X (ScrollView),缩小以填充剩余空间,允许Y 和Z 以全尺寸显示。
实际行为(没有多余的垂直空间) Y 反而缩小了。
我的来源如下。如何修改它以在两种情况下都获得我想要的行为(多余的垂直空间和没有多余的垂直空间)?
<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">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fbe9e7"
android:gravity="center"
android:text="X"
android:textSize="96sp">
</TextView>
</ScrollView>
<TextView
android:id="@+id/text_Y"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f3e5f5"
android:gravity="center"
android:text="Y"
android:textSize="96sp"
app:layout_constraintTop_toBottomOf="@+id/scrollView" />
<TextView
android:id="@+id/text_Z"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e1f5fe"
android:gravity="center"
android:text="Z"
android:textSize="96sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_Y"
app:layout_constraintVertical_bias="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
问题主要源于X 滚动视图在垂直空间有限时需要为0dp,但在垂直空间过多时需要为wrap_content
注意:您可以通过在 Android Studio 中的布局的预览窗格中相应地拖动右下角来演示布局在较少垂直空间的情况下的行为
【问题讨论】:
-
@Racu 抱歉,我认为我的来源格式不正确
标签: android android-layout android-constraintlayout