基本上我有一个带有很长字符串的按钮,它会导致换行。该按钮具有左右边距,但是对于此类多行按钮文本,这些边距会被忽略,因为该按钮占据了父级的整个宽度。
一个明显的解决方案是将布局宽度设置为 0dp,但这会强制使用静态宽度,这意味着对于较短的按钮文本,按钮不再换行。
是否有一个好的解决方案如何保持wrap_content的宽度但仍然不忽略边距?
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:text="@string/longstring"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
最佳答案
关于java - 多行按钮文本忽略按钮边距的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60976661/