2013-07-07 49 views
0

即使我已經有超過一年的Android工作經驗,我仍然在努力使用我的xml佈局。無論如何,我需要創建一個XML佈局如下:查看並不匹配它的父母

enter image description here

我試着用這樣的:

<?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" 
android:weightSum="100"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="5"> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="15"> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="5" > 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="20" > 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="5" > 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="50" > 
</RelativeLayout> 

</LinearLayout> 

enter image description here

,一切看起來正常的,直到那一刻,我想孩子添加一些內部佈局。 所以當我添加listView到RelativeLayout,標記爲3,它不匹配它的 父母,但需要整個屏幕。我如何添加列表視圖內部佈局2和3,以便他們 匹配他們的界限?

+1

也許將所有佈局的'layout_height'設置爲'wrap_content'? –

+0

我試着用match_parent和wrap_content,但在兩種情況下,listView(或imageView,如果我將它添加到佈局1)佔據整個屏幕。 – prowebphoneapp

+0

夥計嘗試從頭到腳。你的方法是正確的,看你使用的圖像是否在你想要的範圍內。 –

回答

2

看看這個演示代碼,可能你可以做一些改變,並將其應用於你的使用。 直接把這段代碼放到你的xml中。

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/com_facebook_button_grey_focused" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.3" 
     android:layout_margin="10dp" 
     > 

     <ListView 
      android:id="@+id/listView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     </ListView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_margin="10dp" 
     > 

     <ListView 
      android:id="@+id/listView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     </ListView> 
    </RelativeLayout> 

</LinearLayout> 
+0

謝謝你的努力,但我只能看到佔據整個屏幕的兩個listView。 – prowebphoneapp

+0

這是爲我工作..你確定你複製粘貼它正確嗎? – Carbon

+0

這不是代碼 - 它是XML! – Simon

相關問題