2013-03-01 136 views
1

請看看我的代碼的拳頭,我要讓像下面的圖片佈局,但兩個列表視圖不起作用:佈局不顯示

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="7" 
     android:baselineAligned="false"> 
     <LinerLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1"><!-- here is the problem--> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:focusableInTouchMode="false" 
       android:text="@string/Subdistrict"/> 

      <ListView 
       android:id="@+id/Subdistrict" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" >  
      </ListView> 

     </LinerLayout> 

     <LinerLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:focusableInTouchMode="false" 
       android:text="@string/Building" 
       android:textColor="#ffffff"/> 
      <ListView 
       android:id="@+id/Building" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
      </ListView> 
     </LinerLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" > 

     <Button 
      android:id="@+id/BuildingSelectOk" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/OK"/> 
     <Button 
      android:id="@+id/BuildingSelectCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/Cancel"/> 
    </LinearLayout> 
</LinearLayout> 

我想實現像下面的圖片佈局:

enter image description here

但兩人的ListView不顯示在所有的,我錯過了什麼?有人幫助我,謝謝。

+6

的一個問題是,你拼寫錯誤'LinearLayout'爲'LinerLayout' – 2013-03-01 03:26:30

+0

嘗試使用'RelativeLayout',而不是'LinearLayout',作爲基地的佈局。 – SudoRahul 2013-03-01 03:29:06

+0

@ A - C哦謝謝, – 2013-03-01 03:42:32

回答

1
"height" to "0dp" though your list will calculate itself. and "weight" to 7? Is it needed? 

的確是這樣,看看這些問題:
Android: trying to understand android:layout_weight
Need help in understand layout_weight="1"

因此,這裏是我的suggesttion:

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="80" 
     android:baselineAligned="false"> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:background="#2fff0000" 
      android:layout_weight="50"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:focusableInTouchMode="false" 
       android:text="Subdistrict"/> 

      <ListView 
       android:id="@+id/Subdistrict" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" >  
      </ListView> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:background="#2f00ff00" 
      android:layout_weight="50"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:focusableInTouchMode="false" 
       android:text="Building" 
       android:textColor="#ffffff"/> 
      <ListView 
       android:id="@+id/Building" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
      </ListView> 
     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="20" 
     android:gravity="center" > 

     <Button 
      android:id="@+id/BuildingSelectOk" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="OK"/> 
     <Button 
      android:id="@+id/BuildingSelectCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Cancel"/> 
    </LinearLayout> 
</LinearLayout> 

當你運行應用程序,你會看到LinearLayout換行2 ListView有不同的背景顏色,所以顯示ListView,所以我認爲問題是你忘記爲它們設置適配器。 試試看,並告訴我結果。