2012-01-16 100 views
0

好吧,所以我有一個片段,我想要顯示兩個TextViews和一個ListView,其中第一個TextView在佈局頂部佔據一小部分,其餘空間均勻分佈在另一個TextView和一個ListView之間。然而,使用我目前的佈局,ListView將其他兩個TextView切割成一個非常小的空間。我認爲這可能與layout_weight attibute有關。Android佈局重量視圖正在關閉

fragment_layout.xml

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

    <TextView 
     android:id="@+id/text_title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Loading ..." 
     android:gravity="center"/> 

    <TextView 
     android:id="@+id/text_description" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="45" 
     android:text="Loading ..." /> 

    <ListView 
     android:id="@+id/list_pre_cert" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="45" 
     android:cacheColorHint="#00000000" 
     android:dividerHeight="0px"> 
    </ListView> 
</LinearLayout> 

當前佈局

Current Layout with the TextViews being cut off

回答

1

如果你想要的高度,以最終被10%,45%,45%,那麼除了要設置您擁有的權重,請爲每個視圖設置layout_height爲0dp。版面權重剩餘空間。