【问题标题】:Unable to wrap labels of buttons inside Material Button Toggle Group无法在 Material Button Toggle Group 内包装按钮标签
【发布时间】:2022-01-13 01:57:42
【问题描述】:

MaterialButtonToggleGroup 中有三个按钮。问题是所有标签都被切断而不是包裹

 <com.google.android.material.button.MaterialButtonToggleGroup
        android:id="@+id/toggle_pomo_time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/margin_medium"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/pomo_card"
        app:singleSelection="true">

        <Button
            android:id="@+id/bt_pomo"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/class_time" />

        <Button
            android:id="@+id/bt_short_break"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/short_break" />

        <Button
            android:id="@+id/bt_long_break"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/long_break" />

    </com.google.android.material.button.MaterialButtonToggleGroup>

我搜索了很多,但找不到任何合适的解决方案。任何帮助将非常感激。谢谢。

【问题讨论】:

    标签: android xml button android-wrap-content materialbutton


    【解决方案1】:

    您不能将它们包装在一行中,因为MaterialButtonToggleGroup 视图的测量宽度被声明为有限,因此它决定在最后将它们省略。您可以验证是否使用了更宽的屏幕或横向模式,如果文本仍在允许的宽度内,文本将换行。

    删除按钮水平填充 android:paddingHorizontal="0dp" 会腾出一点空间。

    但是您可以通过编程方式在两行中执行此操作;因为android:maxLength 属性不适用于here 描述的错误:

    val bt_pomo= findViewById<Button>(R.id.bt_pomo)
    bt_pomo.maxLines = 2
    

    对其他两个按钮重复此操作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 2021-12-03
      • 2018-10-01
      • 2021-06-01
      • 2019-01-25
      • 1970-01-01
      相关资源
      最近更新 更多