我正在尝试使用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设置为中间视图,以防止其被左视图挤压
- 使用Guideline来防止左视图和/或中间视图向右扩展太远
我花了约4个小时尝试让事情正常工作,但目前没有成功。真的很感激帮助。