首页 > 解决方案 > 如果设置为包装内容,填充是否仅包含在视图大小中?

问题描述

在此示例中,不会显示文本,因为它被填充覆盖。

<TextView
     android:padding="250px"
     android:layout_width="500px"
     android:layout_height="500px"
     android:background="@color/yellow"
     android:text="some text"
     android:textColor="@color/red"/>

然而,在这个例子中,填充将被添加到尺寸上,因此会有更大的文本视图和可见文本。

<TextView
      android:padding="250px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@color/yellow"
      android:text="some text"
      android:textColor="@color/red"/>

有没有办法在纯 xml 中设置任意宽度和/或高度,并让视图大小包括填充,就像使用 html 一样?

标签: androidcssxmlkotlin

解决方案


只需决定一个特定的大小并在其上添加填充。

<----------------- 1000px ---------------->
<-- 250px --><---- 500px ----><-- 250px -->

否则,您仍然可以使用边距。


推荐阅读