Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set android:layout_centerHorizontal

In xml you can do the following:

<TextView     ...     android:layout_centerHorizontal="true"     ... /> 

How would I, when I have the instance of TextView, do this programmatically?

like image 636
nhaarman Avatar asked Aug 29 '11 18:08

nhaarman


1 Answers

You should use the addRule method of the RelativeLayout.LayoutParams class.

layoutparams.addRule(RelativeLayout.CENTER_HORIZONTAL); mTextView.setLayoutParams(layoutParams); 
like image 61
Ronnie Avatar answered Sep 30 '22 18:09

Ronnie