2011-05-20 187 views
0

我有以下佈局:如何在一行中放置TextView,第二個TextView應該佔據屏幕的第三部分?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <ImageView android:id="@+id/movie_icon" 
       android:src="@drawable/star_off" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
    <TextView android:id="@+id/name" 
     android:textSize="16sp" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:gravity="left"   
     android:textColor="#FFFFFF" 
     android:textStyle="bold" 
     android:text="aaaaa"/>     
    <TextView android:id="@+id/time" 
     android:textSize="16sp" 
     android:text="1:25 - 2:25" 
     android:layout_height="74dip" 
     android:layout_width="fill_parent" 
     android:gravity="right" 
     android:layout_weight="2" 
     android:background="@drawable/time_background"/> 
</LinearLayout> 

timename TextViews具有相同的寬度,但我需要的time寬度等於name半寬度。我該怎麼做?或者,如何創建name寬度固定(例如,100dip)?

回答

0

試着將它們的寬度設置爲0,並將weight =「1」設置爲您想要的更小,對於您想要的更大的設置weight =「2」。如果這不符合你的要求,我不確定有沒有辦法像你提到的那樣爲它設置像100dip這樣的固定寬度。

+0

'layout_width'不能爲零,它必須被定義(如果我沒有定義它,它顯示正確,但是當運行返回應用程序錯誤時)。那麼如何遵循第二種方法呢? – 2011-05-21 12:21:30

相關問題