2012-05-19 215 views
0

我試圖在另一個線性佈局中嵌入線性佈局。我有地圖視圖。如果我在mapview之後放置嵌入式佈局,它不起作用。如果我把它放在它之前呢?爲什麼,我該怎麼做?嵌入在另一個線性佈局中的線性佈局

下面給出兩個文件:第一個失敗。第二個工程?我想要第一個。

<!--two files. 

The first file does not work. The Check Boxes in an embeded linear layout is below the mapview. It only shows map view. 

The second file works. The Check Boxes in an embeded linear layout is ABOVE the mapview.--> 

<!-- FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE FILE ONE--> 

<?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:background="#A971E5" > 


    <com.google.android.maps.MapView 
     android:id="@+id/mapWhenImClose"  
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:apiKey="0MbR34udiEJdnkplC1F7rK4ZxbSFzdRagCruFDA"/> 
     <!-- had this line but it said depreciated   
     android:enabled="true" --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <CheckBox 
      android:id="@+id/chkShowStreetView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowStreetView" /> 

     <CheckBox 
      android:id="@+id/chkShowSatelliteView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowSatelliteView" /> 

    </LinearLayout> 



</LinearLayout> 


<!--File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two File Two--> 


<?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:background="#A971E5" > 


    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <CheckBox 
      android:id="@+id/chkShowStreetView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowStreetView" /> 

     <CheckBox 
      android:id="@+id/chkShowSatelliteView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowSatelliteView" /> 

    </LinearLayout> 


    <com.google.android.maps.MapView 
     android:id="@+id/mapWhenImClose"  
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:apiKey="0MbR34udiEJdnkplC1F7rK4ZxbSFzdRagCruFDA"/> 
     <!-- had this line but it said depreciated   
     android:enabled="true" --> 

</LinearLayout> 

http://pastebin.com/Tfsec1Mh

+0

邏輯上似乎'MapView'佔用了全因爲你哈哈ve'android:layout_height =「fill_parent」',並且它迫使LinearLayout離開屏幕的底部。如果將其高度設置爲'wrap_content',會發生什麼情況?或者把'MapView'放到它自己的'LinearLayout'中,將它的高度設置爲0dp,對於包含'CheckBoxes'的'LinearLayout'也是一樣的。然後在每個上設置'android:layout_weight'來分配一部分屏幕。 – Squonk

+0

抱歉只是注意到了這個......我也在玩這個方法......我現在的主要目標是學習的不僅僅是獲得一些東西。 –

回答

1

MapView覆蓋了整個屏幕,android:layout_height="fill_parent"

<com.google.android.maps.MapView 
     android:id="@+id/mapWhenImClose"  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:clickable="true" 
     android:apiKey="0MbR34udiEJdnkplC1F7rK4ZxbSFzdRagCruFDA"/> 
     <!-- had this line but it said depreciated   
     android:enabled="true" --> 

編輯:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#A971E5" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/thebar" 
     android:layout_alignParentBottom="true"> 

     <CheckBox 
      android:id="@+id/chkShowStreetView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowStreetView" /> 

     <CheckBox 
      android:id="@+id/chkShowSatelliteView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/strShowSatelliteView" /> 

    </LinearLayout> 


    <com.google.android.maps.MapView 
     android:id="@+id/mapWhenImClose"  
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_above="@id/thebar" 
     android:clickable="true" 
     android:apiKey="0MbR34udiEJdnkplC1F7rK4ZxbSFzdRagCruFDA"/> 
     <!-- had this line but it said depreciated   
     android:enabled="true" --> 

</RelativeLayout> 
+0

感謝您的回覆。我認爲這是正確的方向,但是當我做出這個改變時,我注意到設計師的地圖變成了一條細長的條子。當我在AVD中運行它時,它看起來是一樣的(地圖佔用屏幕並且沒有看到複選框)。 –

+0

我可以添加截圖嗎?我沒有看到任何地方上傳文件。 –

+0

我瞭解正確答案的複選標記,但上/下數字是什麼? –