【发布时间】:2019-07-03 16:17:17
【问题描述】:
我正在尝试使用 ConstrainLayout 构建一个包含三个视图的简单布局:
当左视图中的文本很长时,我想看到这个:
但我得到的是这个 - 左视图向右增长太多并且隐藏了中间视图。
这是我的代码:
<android.support.constraint.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">
<TextView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/left"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
到目前为止我尝试过的一些事情:
- 制作链条并尝试不同的链条样式
- 将 android:minWidth 设置为中间视图以防止它被左视图压扁
- 使用 Guidline 防止左侧和/或中间视图过度向右扩展
我花了大约 4 个小时试图让事情顺利进行,但到目前为止还没有成功。非常感谢帮助。
【问题讨论】:
标签: android android-constraintlayout