【问题标题】:Why can't I place any of android's UI elements on top of a map fragment? [duplicate]为什么我不能将任何 android 的 UI 元素放在地图片段的顶部? [复制]
【发布时间】:2018-02-22 09:19:48
【问题描述】:

我有一个谷歌地图,这是在开始一个新项目时创建地图活动时的默认布局:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xxxxx.xxxxx.xxxxx.xxxxx.MapsActivity" />

当我进入设计视图时,我希望能够将一个按钮拖到地图/片段上。但看起来这种行为是不允许的。

不能将 UI 组件拖到地图上吗?这与iOS不同。

如果是这种情况,我会使用线性布局,然后在其中包含片段和按钮吗?

谢谢。

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    是的,您必须将片段包装在其他布局中,例如 Framelayout。

    【讨论】:

      【解决方案2】:

      您可以使用包含MapView 的标准Fragment,并设置任何View 出现在它上面。

      只要记住将视图放在 xml 中的地图下方即可。

      例如:

      <RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          tools:context="com.paylock.geoalarmlite.page.LocationFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/location_outer_container">
      
          <com.google.android.gms.maps.MapView
              android:id="@+id/map_view"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
          </com.google.android.gms.maps.MapView>
      
          <ImageView
              android:layout_width="..."
              android:layout_height="..."
              android:layout_centerInParent="true"
              android:adjustViewBounds="true"
              android:src="..."
              android:tint="...." />
      

      【讨论】:

        【解决方案3】:

        检查此代码并像这样使用:-

        <?xml version="1.0" encoding="utf-8"?>
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:card_view="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        
        
            <com.google.android.gms.maps.MapView
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        
            <android.support.v7.widget.CardView
                android:id="@+id/card_view"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:layout_gravity="bottom"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:elevation="1dp"
                card_view:cardCornerRadius="8dp">
        
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
        
                    <TextView
                        android:id="@+id/area_no"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="16dp"
                        android:layout_marginTop="4dp"
                        android:text="26"
                        android:textColor="@color/colorPrimaryDark"
        
                        />
        
                    <TextView
                        android:id="@+id/area_name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/area_no"
                        android:layout_marginLeft="16dp"
                        android:layout_marginTop="10dp"
                        android:maxLines="1"
                        android:text="Velachery Rd Dandeeswarar Nagar"
                        android:textColor="@color/colorPrimaryDark" />
        
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/area_name"
                        android:layout_margin="8dp"
                        android:orientation="horizontal"
                        android:weightSum="2">
        
                        <Button
                            android:id="@+id/btEnterManually"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="@drawable/round_button"
                            android:text="select manual location"
                            android:textColor="@color/colorLogo"
                            android:textSize="12sp" />
        
                        <View
                            android:layout_width="2dp"
                            android:layout_height="match_parent" />
        
                        <Button
                            android:id="@+id/bt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="@drawable/round_button"
                            android:text="Confirm order address"
                            android:textColor="@color/colorLogo"
                            android:textSize="12sp" />
        
        
                    </LinearLayout>
                </RelativeLayout>
        
            </android.support.v7.widget.CardView>
        
        
        </FrameLayout>
        

        【讨论】:

          猜你喜欢
          • 2010-11-03
          • 2018-10-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-07
          相关资源
          最近更新 更多