为什么可以';我不能放置任何android';在地图片段上的UI元素是什么?
我有一个谷歌地图,这是启动新项目时创建地图活动时的默认布局:为什么可以';我不能放置任何android';在地图片段上的UI元素是什么?,android,android-layout,Android,Android Layout,我有一个谷歌地图,这是启动新项目时创建地图活动时的默认布局: <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:na
<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不同
如果是这样,我会使用线性布局,然后在其中包含片段和按钮吗
谢谢。是的,您必须将片段包装到其他布局中,如Framelayout。您可以使用包含
地图视图的标准片段,只需将任何视图设置为显示在其上即可
只需记住在xml中将视图放在地图下方即可
例如:
检查此代码并像这样使用:-
<?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>
<?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>