【发布时间】:2020-07-13 13:02:59
【问题描述】:
基本上我有一个带有很长字符串的按钮,它会导致换行。按钮有左右边距,但是由于按钮占据了父级的整个宽度,因此多行按钮文本会忽略这些边距。
一个明显的解决方案是将布局宽度设置为 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 android button margin line-breaks