2016-04-25 15 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