I have created 5 TextView programmatically, now i want to set few Parameters/Attributes of their such as Gravity, Layout_Gravity, etc.
I know we can set it in XML layout at Design-time:
android:gravity="center|center_horizontal|center_vertical"
android:layout_gravity="center|center_horizontal|center_vertical"
But, How can we set Gravity/Layout_Gravity kinds of Attributes programmatically?
You can set the gravity of TextView programmatically using setGravity(int))
Probably you can set layout_gravity like this(I've not yet tested this) :
TextView can let its parent know about layout preferences using
setLayoutParams(ViewGroup.LayoutParams params)
LayoutParams params=new LayoutParams(this, attrSet);
tv.setLayoutParams(params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With