ConstraintLayout 可以帮助将右侧项目流到下一行吗?

can ConstraintLayout help to flow the right side item to next line?

让 textView 点亮到左边缘,它的宽度可能会增加。让其他一些 textView 在其右对齐单行。

当左侧 textView 宽度增加时,希望将右侧的 textView 下推到下一行:

[AAA]  [BBB] 

当左边一个宽度增长时:

[AAA AAA AAA AAA AAA]

[BBB]

想看到一些使用 ConstraintLayout 自动将右侧项目推到下一行的示例,但找不到任何示例。

ContraintLayOut 是可行的,或者有人知道一些示例吗?

Update:下面的答案仍然有效,但从 ConstraintLayout 2.0 开始,使用 Flow helper. See Stack Overflow 回答一个例子。


AFAIK,从一行到下一行的流动视图不是 ConstraintLayout 可以做的。然而,FlexboxLayout 可以轻松做到这一点。

Here是对该技术的初步介绍。 Play 商店中也有一些不错的应用程序可以用来调整布局。

FlexboxLayout can be interpreted as an advanced LinearLayout because both layouts align their child views sequentially. The significant difference between LinearLayout and FlexboxLayout is that FlexboxLayout has a feature for wrapping.

经过四处寻找,得出的结论是ConstraintLayout是将布局的视图层级展平,避免嵌套,优化视图层级。 正如@Cheticamp 指出的那样 "ConstraintLayout does not have that particular capability"。所以结束这个问题。

你可以这样使用com.google.android.material.chip.ChipGroup

<com.google.android.material.chip.ChipGroup
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_marginTop="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/title">
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="aaaaaaa"
        android:textSize="10sp"/>

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bbbbbb"/>

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="cccccccc"/>

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="fffffffff"/>

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hhhhhhh"/>
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="trtr"/>
    </com.google.android.material.chip.ChipGroup>

see more here

我知道我来晚了,但是对于仍然订阅这个问题的任何人来说,截至今天 ConstraintLayout 2.0(刚刚在 beta1 中推出)支持一个新的 ConstraintHelper 称为 Flow 使用它可以在 ConstraintLayout.

中满足您的特定要求

Flow

The following are the release notes for beta1