【问题标题】:Linear Layout Embeded in Another Linear Layout线性布局嵌入另一个线性布局
【发布时间】:2012-05-19 19:07:02
【问题描述】:

我正在尝试将线性布局嵌入到另一个线性布局中。我有一个地图视图。如果我在 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

【问题讨论】:

  • 从逻辑上讲,MapView 似乎占据了整个屏幕,因为您有android:layout_height="fill_parent",它迫使LinearLayout 离开屏幕底部。如果将其高度设置为 wrap_content 会发生什么?或者将MapView 放在它自己的LinearLayout 中,将其高度设置为0dp,对于包含CheckBoxesLinearLayout 设置相同的高度。然后在每个上设置android:layout_weight来分配屏幕的比例。
  • 很抱歉刚刚注意到这一点……我也不太喜欢这种方法……我现在的主要目标是学习更多,而不仅仅是把东西拿出来。

标签: android xml android-layout android-linearlayout


【解决方案1】:

您的MapViewandroid: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>

【讨论】:

  • 感谢您的回复。我认为这是正确的方向,但是当我进行此更改时,我在设计器中注意到地图变成了一条细条。当我在 AVD 中运行它时,它看起来是一样的(地图占据了屏幕并且看不到复选框)。
  • 我可以添加截图吗?我没有看到可以上传文件的地方。
  • 我理解正确答案的复选标记,但上/下数字是什么?
  • @TheArchitect 看看我编辑的 xml 是否有帮助。您可以在顶部的栏中添加带有图像标签的图像(如果您编辑问题,您会看到)。如果答案有帮助/没有帮助,您可以对其投赞成票/反对票,而所有者将因此获得/失去一些声誉点数。
  • 好的,谢谢兄弟!当然地图应该是第一位的,但我明白你在说什么。 :-) 再次感谢您
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-17
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多