我在一個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>
我已經搜索了很多,但找不到任何合適的解決方案。任何幫助將非常感激。謝謝你。
uj5u.com熱心網友回復:
您不能將它們包裝在一行中,因為MaterialButtonToggleGroup視圖的測量寬度被宣告為有限的,因此它決定在最后將它們橢圓化。您可以驗證是否使用了更寬的螢屏或橫向模式,如果文本仍在允許的寬度內,則文本會換行。
洗掉按鈕水平填充android:paddingHorizontal="0dp"會騰出一點空間。
但是你可以以編程方式在兩行中做到這一點;因為android:maxLength屬性不適用于此處描述的錯誤:
val bt_pomo= findViewById<Button>(R.id.bt_pomo)
bt_pomo.maxLines = 2
并對其他兩個按鈕重復此操作
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381897.html
標籤:安卓 xml 按钮 android-wrap-content 材质按钮
上一篇:華為鑰匙環服務攜手航班管家與高鐵管家,為兩億出行用戶打造美好出行體驗
下一篇:HTML按鈕標簽css
