2012-05-19 171 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

我了解正确答案的复选标记,但上/下数字是什么? –