ConstraintLayout版本:2.0.0-beta3
在约束流布局中添加了视图。具有匹配约束的放置视图,如果视图高度是自动换行内容,而内容高度增加则行重叠。在这里,我添加了代码段
步骤:
1。创建的流布局
2。创建的视图以宽度作为匹配约束,高度作为包装内容
3.flow_wrapMode =“链”
4。如果我向视图中添加更多内容,则行会重叠
代码飞船:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.helper.widget.Flow
android:id="@+id/flow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:constraint_referenced_ids="button2,button3,button4,button5,button6,button7"
app:flow_maxElementsWrap="3"
app:flow_wrapMode="chain"
tools:ignore="MissingConstraints"></androidx.constraintlayout.helper.widget.Flow>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button1 Button2 Button2 Button2 Button2 Button2 Button2"
android:background="@android:color/holo_blue_dark"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_dark"
android:text="Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_green_light"
android:text="Button3"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:text="Button 1 Button 2 Button 2 Button2 Button2 Button2 Button2 ton2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_light"
android:text="Button2 ton2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2 ton2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_purple"
android:text="Button3 Button1 Button2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2 Button1 Button2 Button2 Button2 Button2 Button2 Button2"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
截屏: