2011-03-16 109 views
2

這裏是我的佈局:的EditText下的ListView顯示

<?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"> 

    <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@android:id/list" /> 
    <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/search" android:hint="Filter results" /> 

是什麼原因造成我ListView掩蓋我的編輯文本?

回答

10

也許嘗試這樣做:

<ListView 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_width="fill_parent" android:id="@android:id/list"/> 
<EditText 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/search" 
    android:hint="Filter results"/> 

這樣,你的ListView將增長到填補只未使用的空間無論其自己的內容要求。

0

您可以在列表視圖中使用weight = 1和height 0dp: 由於fill_parent已棄用,因此請使用match_parent。

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

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <EditText 
     android:id="@+id/search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Filter results" /> 
</LinearLayout>