【问题标题】:Is padding only included in a view size if its set to wrap content?如果设置为包装内容,填充是否仅包含在视图大小中?
【发布时间】:2021-02-21 01:47:14
【问题描述】:

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

<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 一样?

【问题讨论】:

    标签: android css xml kotlin


    【解决方案1】:

    只要确定一个特定的大小并在上面添加填充。

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

    否则你仍然可以使用边距。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 2013-03-08
      • 2018-12-20
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      相关资源
      最近更新 更多