Nate Nate - 1 year ago 123
Android Question

Android set the gravity for a TextView programmatically

I can use

in xml on a textview to get my desired results, but I need to do this programmatically. My textview is inside a
if that matters in a

I have tried:

LayoutParams layoutParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

But if I understand correctly, that would apply it to the
, not the textview?

Answer Source
labelTV.setGravity(Gravity.CENTER | Gravity.BOTTOM);

Also, are you talking about gravity or about layout_gravity? The latter won't work in a RelativeLayout.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download