1

I have a google map and this is the default layout when creating a map activity when starting a new project:

<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" />

When I go into design view I would like to be able to drag a button onto the map/fragment. But it would appear that behaviour isn't allowed.

Is it not possible to drag a UI components onto the map? That is then different to iOS.

If that's the case would I use a linear layout and then include the fragment and button in that?

Thanks.

Mike
  • 1,281
  • 3
  • 14
  • 41

3 Answers3

1

Yes, you have to wrap your fragment in some other layout like Framelayout.

honey_ramgarhia
  • 537
  • 7
  • 15
1

You can use a standard Fragment containing a MapView and just set any View to appear over it.

Just remember to place the view below the map in the xml.

E.g:

<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="...." />

payloc91
  • 3,724
  • 1
  • 17
  • 45
0

Check this code and use like this:-

<?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>
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30