Android:以编程方式设置textview的一个填充
16lz
2021-01-22
I want to set the top padding of a textview programmatically. I know you can do this with the method setPadding(). But the problem is that this method requires 4 parameters: left, top, right, bottom. I don't want to change the left, right and bottom, I just want to change the top padding.
我想以编程方式设置textview的顶部填充。我知道你可以用方法setPadding()来做到这一点。但问题是这种方法需要4个参数:左,上,右,下。我不想改变左,右和底,我只是想改变顶部填充。
Is that possible?
那可能吗?
2 个解决方案
#1
57
use
使用
yourTextView.setPadding(0, 10, 0, 0);
Adjust only the parameters you need and set the other ones to zero.
仅调整所需的参数,并将其他参数设置为零。
If you need to preserve other existing paddings, use yourView.getPaddingLeft()
, yourView.getPaddingTop()
and so on.
如果需要保留其他现有的填充,请使用yourView.getPaddingLeft(),yourView.getPaddingTop()等。
更多相关文章
- 转发可变数量的参数以通过椭圆运算符接受可变数量的参数
- 准备语句SQL异常“无输入参数”
- 使用Java中的Scala:将函数作为参数传递
- 如何在命令中传递对象参数?
- 如何在Javascript中解析URL查询参数?(复制)
- Java-控制台传递参数