Bravo
Bravo

Reputation: 1139

How to disable google maps touch events through a layout? (android)

Here is a screenshot of my application

enter image description here

If I touch the legend content, I can still move the map or click markers through the legend layout. Here is my XML

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

<LinearLayout
    android:id="@+id/legend_popover"
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="10dp"
    android:background="@color/white"
    android:orientation="vertical"
    android:radius="7dp"
    android:visibility="gone">
...

I don't want to disable the whole map, I want to disable gestures only on the legend popover. Thank you @antonio for the answer

Upvotes: 3

Views: 5486

Answers (4)

Mattia Ferigutti
Mattia Ferigutti

Reputation: 3708

If you're using Kotlin:

mapView.getMapAsync {
    it.uiSettings.setAllGesturesEnabled(false)
}

Upvotes: 0

Pei
Pei

Reputation: 11643

Another decent way to achieve the same.

googleMap.getUiSettings().setAllGesturesEnabled(false);

Upvotes: 6

antonio
antonio

Reputation: 18242

Add android:clickable="true" to your legend_popover layout

Upvotes: 5

Hackose
Hackose

Reputation: 722

Use this

mMapFragment.getView().setClickable(false);

Upvotes: 6

Related Questions