Setting Text View Attributes

I created 5 TextView programmatically, now I want to set some parameters / attributes like Gravity, Layout_Gravity etc.

I know that we can set it in the XML layout in Design-time:

android:gravity="center|center_horizontal|center_vertical"
android:layout_gravity="center|center_horizontal|center_vertical"

But, how can we set attribute types Gravity / Layout_Gravity attributes programmatically ?

+3
source share
2 answers

You can set gravity programmatically with setGravity(int))

Perhaps you can install layout_gravityas follows (I have not tested this yet):

TextView can tell parents about layout settings with

setLayoutParams(ViewGroup.LayoutParams params)
LayoutParams params=new LayoutParams(this, attrSet);
tv.setLayoutParams(params);
+4

. View, , " XML". XML , , .

0

Source: https://habr.com/ru/post/1777392/


All Articles