Android: set just one padding of textview programmatically

Xander picture Xander · Mar 21, 2013 · Viewed 46.1k times · Source

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.

Is that possible?

Answer

Droidman picture Droidman · Mar 21, 2013

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.