Issue
I'm trying to add an overlay to my google map which is fixed in the center of the screen so users can use it to finely selected a location.
Currently the code below draws a mapview with a centered crosshair image but as the button is below the mapview the center of the map changes and the crosshair no longer represents the center point of the map which has been moved upwards by the height of the button.
I've looked at Android - Showing a crosshair in the center of my Google Map but it seems it is only suitable for v1 :(
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/locationpicker_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/locationpicker_add_venue"
android:clickable="true"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crosshairs"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/locationpicker_add_venue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text = "Add new venue here"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Solution
In order to achieve this effect I used a relative layout wrapped around the map fragment with an imageview centered. For the example see below;
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/locationpicker_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crosshairs"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/locationpicker_add_venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "Add new venue here"
style="@style/Buttonpurple_style"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Answered By - Garbit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.