2016-04-25 87 views
1

因此,根据我的程序流程,在程序生命周期中,我的活动中有一行View由TextViews自定义填充。问题在于,当生成TextView时,它们彼此相邻(通过我设置的布局参数)。如何根据TextView编号分别更改一行中TextView的宽度?

防爆

TextView_1 TextView_2 TextView_3 

我要的是,根据若干意见(即acitvity开始每一次,都产生TextViews的具体数)genarated 采取具体并在活动中等宽,下面的lke:

Image

我该如何成功?

每一个小小的帮助表示赞赏。

回答

1

您必须使用重量:

例如

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weightSum="3" 
    android:orientation="horizontal" 
    android:layout_gravity="center"> 

    <TextView 
    android:layout_height="wrap_content"  
    android:layout_weight="1" 
    android:layout_width="0dp"/> 

    <TextView 
    android:layout_height="wrap_content"  
    android:layout_weight="1" 
    android:layout_width="0dp"/> 

    <TextView 
    android:layout_height="wrap_content"  
    android:layout_weight="1" 
    android:layout_width="0dp"/> 


</LinearLayout> 

到重量分布是很重要的。

如果你把10的总重量必须是10

如果你把3-3的总重量必须在3。

换句话说1 + 1 + 1 = 3所以处理3个元素的宽度。

或3.3 + 3.3 + 3.3 = 9.9

+0

如果您不想留下空白空间,也可以避免使用weightSum。 –

+0

是的,你是对的。 – josedlujan

+0

感谢您的回答!那么,如果不使用weightSum,我只是相应地使用weigth? – Kanellis