2013-07-10 89 views
0

我有以下佈局安卓:線性佈局固定寬度

LinearLayout 
    orientation:horizontal 

    CheckBox 
     visibility:invisible 
     layout_weight:0 

    TextView 
     layout_weight:1 

    TextView 
     layout_weight:1 

    TextView 
     layout_weight:1 

    TextView 
     layout_weight:1 

點擊時,我有我的動作條的編輯按鈕,使得複選框可見

的問題是,當所有顯示的複選框TextViews向右移動,

有什麼辦法可以使CheckBox列的固定寬度,以便它不會影響其他部分?

+0

您是否嘗試過爲複選框設置layout_weight:1呢? –

+0

只需刪除所有layout_weight,如果它們完全相同,則沒有用處。 –

+0

@StefandeBruijn當尺寸改變時,layout_weight使列具有固定的寬度並在佈局上伸展。 –

回答

0

我測試此代碼,可見當它不會有跳:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <CheckBox 
     android:visibility="invisible" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

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

如果您在任何時間,讓您的複選框的可見性消失也不會「儲備」的空間。