2013-01-08 29 views

回答

-1

確保您設置高度0dp,然後設置權重對所有的意見,1

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="Hello World, MyActivity" 
     android:background="#f00" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="Hello World, MyActivity" 
     android:background="#00f" 
     /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="Hello World, MyActivity" 
     android:background="#0f0" 
     /> 
</LinearLayout> 

當視圖設置爲走了剩下的意見,將填補它們的比值的屏幕。也就是說,如果你設置的第三視圖去第一2次會佔用每個可用空間的50%,在佈局

此外,如果你想只有剩下的意見佔據中每一個空間的1/3(即2/3使用,並留下1/3空)您的隱藏視圖設置爲不可見沒有去

0

這似乎改變其重量的變化被渲染後,必須在視圖上調用refreshDrawableState():

((LinearLayout.LayoutParams) btnFav.getLayoutParams()).weight = 3f; 
btnFav.refreshDrawableState();