问题描述
我已经创建了5 TextView的编程,现在我想设置自己如重力,Layout_Gravity等。
I have created 5 TextView programmatically, now i want to set few Parameters/Attributes of their such as Gravity, Layout_Gravity, etc.
我知道我们可以在设计时设置它在XML布局:
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"
但是,我们如何设置重力/ Layout_Gravity种属性的编程
推荐答案
您可以设置的TextView的严重性编程方式使用setGravity(INT),指的)
You can set the gravity of TextView programmatically using setGravity(int), refer http://developer.android.com/reference/android/widget/TextView.html#setGravity(int)
也许你可以设置layout_gravity像这样(我没有测试过这一点):
Probably you can set layout_gravity like this(I've not yet tested this) :
TextView中可以让其父了解布局preferences使用setLayoutParams(ViewGroup.LayoutParams PARAMS)
TextView can let its parent know about layout preferences using setLayoutParams(ViewGroup.LayoutParams params)
LayoutParams params=new LayoutParams(this, attrSet);
tv.setLayoutParams(params);
这篇关于设置TextView中的属性编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!