android - 如果设置为包装内容,填充是否仅包含在视图大小中?
问题描述
在此示例中,不会显示文本,因为它被填充覆盖。
<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 一样?
解决方案
只需决定一个特定的大小并在其上添加填充。
<----------------- 1000px ---------------->
<-- 250px --><---- 500px ----><-- 250px -->
否则,您仍然可以使用边距。
推荐阅读
- javascript - 如果变量是空字符串,则附加各种 div 元素
- http - 假证书如何拦截 SSL 流量
- sql-server - 将两张表放在一起进行求和
- python - “这是什么意思:key=lambda x: x[-1]?”
- excel - 停止从修剪值到列的固定宽度文本
- javascript - 如何使流从一个管道到另一个管道nodejs
- python - 在python中使用后删除文件对象
- javascript - 如何将嵌套 json 属性的值分配给父对象?
- python - TypeError 和 RuntimeError 工作正常后第一次运行
- python - 数据框是和对象而不是普通数据框?