jyomin
jyomin

Reputation: 1967

Adding a ImageView on top of the MapView

I want to draw free hand drawing on the map view to achieve that I am making my map non-interactive by adding a view on top of fragment and working on MotionEvents and Projection. For that I have taken a button and on the click of that button i am making my imageview visible so it comes on the foreground and the map view goes in backgound but Its not working as So anybody has any idea where i m getting wrong...I m sharing my xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
     >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:id="@+id/draw_btn"
        android:text="@string/button" />

     <ImageView
    android:id="@+id/draw_view"


    android:layout_below="@+id/draw_btn"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/ic_launcher"
    android:visibility="gone"
    />

     <com.google.android.gms.maps.MapView
        android:id="@+id/map"
         android:layout_below="@+id/draw_btn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>

Upvotes: 0

Views: 1525

Answers (2)

James Wald
James Wald

Reputation: 13734

Your MapView is on top of the ImageView because children are layered on top of each other in the order they are added, e.g. the order they appear in the RelativeLayout element. If you move the MapView up, before the ImageView, it will be presented underneath the ImageView. Perhaps you are thinking that android:layout_below refers to the Z-ordering of the views? It actually controls the vertical position.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent">

    ... button ...

    <com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:layout_below="@+id/draw_btn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ImageView
        android:id="@+id/draw_view"
        android:layout_below="@+id/draw_btn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="@drawable/ic_launcher"
        android:visibility="gone" />

</RelativeLayout>

If this doesn't work, there may be more going on with the Window. For example, the YouTube Player API cuts a hole in the Window so it can detect when other views are presented on top of the video area, immediately stopping playback when that happens.

Upvotes: 1

Hariharan
Hariharan

Reputation: 24853

Try this..

Use LinearLayout and that orientation give as vertical and try

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
   android:orientation="vertical"
     >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:id="@+id/draw_btn"
        android:text="@string/button" />

     <ImageView
    android:id="@+id/draw_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/ic_launcher"
    android:visibility="gone"
    />

     <com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

Upvotes: 0

Related Questions