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()等。

更多相关文章

  1. 转发可变数量的参数以通过椭圆运算符接受可变数量的参数
  2. 准备语句SQL异常“无输入参数”
  3. 使用Java中的Scala:将函数作为参数传递
  4. 如何在命令中传递对象参数?
  5. 如何在Javascript中解析URL查询参数?(复制)
  6. Java-控制台传递参数

随机推荐

  1. Android 实现显示文字的Gallery
  2. android Setting中隐藏项
  3. Android 网站资源收集大全
  4. Android 修改 以太网 IP地址
  5. Android各种Layout用到的一些重要的属性
  6. android:gravity与android:layout_gravit
  7. 3.EditText
  8. andriod RelativeLayout布局居中
  9. Android应用程序进程启动过程(后篇)
  10. Android布局属性说明