How to add buttons at the top of the map fragment API v2 layout

I am trying to show maps in android using v2 API.
I want the user interface to have something like this. But when I try to add a button in the layout, it does not affect the output
I can get cards without buttons .
I need buttons for integration with the map as shown below
Code for Mylayout.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MapActivity" > <RelativeLayout android:layout_width="match_parent" android:layout_height="48dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioGroup android:id="@+id/radio_group_list_selector" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center_horizontal|center_vertical" android:gravity="center_horizontal" android:orientation="horizontal" android:layout_weight="1" > <RadioButton android:id="@+id/radioPopular" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/Popular" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton" android:layout_marginBottom="4dp" android:layout_marginTop="4dp" android:layout_marginLeft="4dp" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="wrap_content" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="#aaa" /> <RadioButton android:id="@+id/radioAZ" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/AZ" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton2" android:layout_marginBottom="4dp" android:layout_marginTop="4dp" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="wrap_content" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="#aaa" /> <RadioButton android:id="@+id/radioCategory" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/Category" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton2" android:layout_marginBottom="4dp" android:layout_marginTop="4dp" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="wrap_content" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="#aaa" /> <RadioButton android:id="@+id/radioNearBy" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/NearBy" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton3" android:layout_marginBottom="4dp" android:layout_marginTop="4dp" android:layout_marginRight="4dp" android:textColor="@drawable/textcolor_radiobutton" /> </RadioGroup> </LinearLayout> <!-- For Horizontal Line--> <View android:layout_width="match_parent" android:layout_height="1dip" android:layout_marginLeft="4dip" android:layout_marginRight="4dip" android:background="#aaa" android:layout_alignParentBottom="true"/> </RelativeLayout> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:scrollbars="vertical" class="com.google.android.gms.maps.SupportMapFragment"/> </RelativeLayout> 

Maps with Button

+54
android android-layout uibutton google-maps
Feb 04 '13 at 19:33
source share
3 answers

Perhaps an easier solution is to set the overlay in front of your map using FrameLayout or RelativeLayout and treat them like regular buttons in your activity. You must declare your layers back in front order, for example, the map in front of the buttons. I changed the layout, simplified it a bit. Try the following layout and see if it works for you:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MapActivity" > <fragment xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:scrollbars="vertical" class="com.google.android.gms.maps.SupportMapFragment"/> <RadioGroup android:id="@+id/radio_group_list_selector" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" android:background="#80000000" android:padding="4dp" > <RadioButton android:id="@+id/radioPopular" android:layout_width="0dp" android:layout_height="match_parent" android:text="@string/Popular" android:gravity="center_horizontal|center_vertical" android:layout_weight="1" android:background="@drawable/shape_radiobutton" android:textColor="@color/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioAZ" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/AZ" android:layout_weight="1" android:background="@drawable/shape_radiobutton2" android:textColor="@color/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioCategory" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/Category" android:layout_weight="1" android:background="@drawable/shape_radiobutton2" android:textColor="@color/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioNearBy" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/NearBy" android:layout_weight="1" android:background="@drawable/shape_radiobutton3" android:textColor="@color/textcolor_radiobutton" /> </RadioGroup> </FrameLayout> 
+83
Feb 05
source share

Button Above The Map

If this is what you want ... just add a button inside the snippet.

 <fragment xmlns:android="http://schemas.android.com/apk/res/android" 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.example.LocationChooser"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|top" android:text="Demo Button" android:padding="10dp" android:layout_marginTop="20dp" android:paddingRight="10dp"/> </fragment> 
+46
Feb 27 '15 at 7:17
source share

Extension response Almeida. I’m editing the code a bit here. since the previous code hid the gps location icon, I made the following path that worked better.

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RadioGroup android:id="@+id/radio_group_list_selector" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" android:background="#80000000" android:padding="4dp" > <RadioButton android:id="@+id/radioPopular" android:layout_width="0dp" android:layout_height="match_parent" android:text="@string/Popular" android:gravity="center_horizontal|center_vertical" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioAZ" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/AZ" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton2" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioCategory" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/Category" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton2" android:textColor="@drawable/textcolor_radiobutton" /> <View android:id="@+id/VerticalLine" android:layout_width="1dip" android:layout_height="match_parent" android:background="#aaa" /> <RadioButton android:id="@+id/radioNearBy" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/NearBy" android:layout_weight="1" android:button="@null" android:background="@drawable/shape_radiobutton3" android:textColor="@drawable/textcolor_radiobutton" /> </RadioGroup> <fragment xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" android:scrollbars="vertical" /> 

+3
Feb 05 '13 at 20:25
source share



All Articles