一、强制约束
app:layout_constrainedWidth=”true|false” //默认false app:layout_constrainedHeight=”true|false” //默认false
例:控件B在控件A右边和父右边之间居中显示
?当B内容过多,则超出A右边限制
设置app:layout_constrainedWidth="true",则可以在之间显示
补充:另外可以通过该属性可以轻松满足此需求(控件A、B横向顺序链表排列,B始终单行显示全部,A包裹内容显示,当A内容过多时换行显示)
当A内容少时
当A内容多时
?
?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tv_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_b"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
app:layout_constrainedWidth="true"
android:background="#ff0000"/>
<TextView
android:id="@+id/tv_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv_a"
android:text="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
android:background="#00ff00"/>
</android.support.constraint.ConstraintLayout>
?
?
|