【问题标题】:Can I use a Flow helper with RadioButtons?我可以使用带有 RadioButtons 的 Flow 助手吗?
【发布时间】:2019-11-19 22:42:25
【问题描述】:

我在 SO 上找到了以下关于约束布局流助手 ConstraintLayout Flow helper example 的帖子,并想知道它们是否可以与单选按钮一起使用。

我几乎找不到关于在任何地方使用流助手的信息。

我尝试将以下内容添加到 RadioGroup 内的布局中。

    <androidx.constraintlayout.helper.widget.Flow
        android:id="@+id/flow1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="10dp"
        app:constraint_referenced_ids="radioButton, radioButton2, radioButton3"
        app:flow_horizontalBias="0"
        app:flow_horizontalGap="10dp"
        app:flow_horizontalStyle="packed"
        app:flow_verticalBias="0"
        app:flow_wrapMode="chain"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

当我尝试运行应用程序时,我收到以下错误:

Android resource linking failed
C:\AndroidProjects\MyApp\app\src\main\res\layout\activity_main.xml:158: error: attribute flow_horizontalBias (aka com.domain.myapp:flow_horizontalBias) not found.
C:\AndroidProjects\MyApp\app\src\main\res\layout\activity_main.xml:158: error: attribute flow_horizontalGap (aka com.domain.myapp:flow_horizontalGap) not found.
C:\AndroidProjects\MyApp\app\src\main\res\layout\activity_main.xml:158: error: attribute flow_horizontalStyle (aka com.domain.myapp:flow_horizontalStyle) not found.
C:\AndroidProjects\MyApp\app\src\main\res\layout\activity_main.xml:158: error: attribute flow_verticalBias (aka com.domain.myapp:flow_verticalBias) not found.
C:\AndroidProjects\MyApp\app\src\main\res\layout\activity_main.xml:158: error: attribute flow_wrapMode (aka com.domain.myapp:flow_wrapMode) not found.
error: failed linking file resources.

【问题讨论】:

    标签: android android-constraintlayout androidx


    【解决方案1】:

    在 gradle 中使用 constraintlayout:2.0.0-alpha5

    参考Flow

    【讨论】:

    • 谢谢。这消除了错误。它似乎没有包裹单选按钮,所以我不确定这是否意味着我不能将 Flow 与单选按钮一起使用,或者我的布局文件需要做其他事情。
    【解决方案2】:

    是的,您可以使用ConstraintLayout(和Flow)来安排RadioButton,但您必须使用一个可识别ConstraintLayout 的RadioGroup 小部件来管理RadioButton 小部件。

    请访问https://github.com/samlu/ConstraintRadioGroupblRadioGroup 小部件应该是您正在寻找的。​​p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      相关资源
      最近更新 更多