【发布时间】:2020-10-28 23:00:45
【问题描述】:
如果您有一个带有layout_width="wrap_content" 的 TextView,并且它必须换行以包含文本,那么它将调整其宽度以用完所有可用空间(考虑边距等)。但是为什么视图的末尾有填充?我只是告诉它wrap_content,所以它应该包装那个内容!这似乎是一个错误,这在股票 Messenger 应用程序的聊天 UI 中可见。 (虽然图片来自我自己的应用程序。但额外的空间绝对不是 9 补丁中的。)
有什么解决方法吗?
更新:响应者/评论者错过了重点。也许我上传的图片具有误导性,因为它是从我的应用程序中设计的。任何 TextView 都会出现此问题,您可以通过设置背景样式来查看视图边界将不再紧密。我上传了一张不同的图片。这是图像中 TextViews 的 XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#dddddd"
android:text="This doesn't wrap"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_gravity="center_horizontal"
android:background="#dddddd"
android:text="This wraps and look, the bounds does not fit tight against the right edge of text"
/>
【问题讨论】:
-
也许这个词不合适?也许你的 9patch 有一些内在背景?
-
我更新了我的答案,它现在应该涵盖你的观点