2011-06-17 78 views
0

我想顯示一個EditText和一個按鈕水平和他們下面我想要顯示一個List(ListView)。我嘗試了這一點,但它似乎只能看到第一個佈局,之後沒有任何其他內容。Android佈局不顯示我所有的組件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="1dip" 
> <LinearLayout 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:weightSum="4"> <EditText 
android:id="@+id/search_txt" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_weight="3" 
/> 
<Button 
android:id="@+id/search_button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Go" 
android:layout_weight="1" 
/> </LinearLayout> <!-- <EditText 
android:id="@+id/testedit_txt" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_weight="3" 
/> 
--> <ListView android:id="@+id/android:list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
<TextView android:id="@+id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/text2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:textAppearance="?android:attr/textAppearanceSmall" /></LinearLayout> 

我也曾嘗試和註釋行(EditText上),並且還沒有顯示我什麼... 任何想法? 謝謝!

回答

0

添加

layout_weight="1" 

到你的水平佈局。 如果你也想看到這些,你需要在底部的TextView中添加類似的行。

您目前的問題是,您將其中一個設置爲fill_parent,因此當它到達ListView時,沒有空間可用。

0

您正在使用兩個嵌套的LinearLayout與fillParent ...你做錯了。 爲什麼不使用RelativeLayout?

0

試試這個:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="1dip"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:weightSum="4" 
     android:layout_height="wrap_content"> 
     <EditText 
      android:id="@+id/search_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" /> 
     <Button 
      android:id="@+id/search_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Go" 
      android:layout_weight="1" /> 
    </LinearLayout> <!-- <EditText android:id="@+id/testedit_txt" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="3" /> --> 
    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1"/> 
    <TextView 
     android:id="@+id/text1" 
     android:layout_width="fill_parent" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_height="wrap_content" 
     android:text="qwe" /> 
    <TextView 
     android:id="@+id/text2" 
     android:layout_width="fill_parent" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_height="wrap_content" 
     android:text="qwe" /> 
</LinearLayout> 
0

我假設你想的EditText和按鈕,在頂部,底部兩個TextViews,和ListView控件來填補中間的可用空間。如果是這樣的話,那麼你需要調整你的layout_height的,並添加一個android:layout_weight="1"到你的ListView:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="1dip"> 
    <LinearLayout android:orientation="horizontal" 
     android:layout_width="fill_parent" android:weightSum="4" 
     android:layout_height="wrap_content"> 
     <EditText android:id="@+id/search_txt" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="3" /> 
     <Button android:id="@+id/search_button" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="Go" 
      android:layout_weight="1" /> 
    </LinearLayout> <!-- <EditText android:id="@+id/testedit_txt" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="3" /> --> 
    <ListView android:id="@+id/android:list" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" /> 
    <TextView android:id="@+id/text1" android:layout_width="fill_parent" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_height="wrap_content" /> 
    <TextView android:id="@+id/text2" android:layout_width="fill_parent" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 
0

試試這個....爲我工作:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pagelayout"> 

    <FrameLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/content"> 
     <ListView android:id="@+id/android:list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    </FrameLayout> 

    <LinearLayout android:layout_height="wrap_content" 
     android:id="@+id/button_layout" 
     android:layout_width="fill_parent" android:gravity="center" android:layout_above="@+id/content"> 

     <Button android:id="@+id/search_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Go" 
      android:layout_weight="1" 
      /> 

      <EditText> 
      android:id="@+id/search_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      </EditText> 
    </LinearLayout> 

    </RelativeLayout>