0

I am showing one image view that showing a svg map. my requirement is to get particular svg path click event. i don't know what is the process or any idea about this scenario

this is my xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none">

        <ImageView
            android:id="@+id/richPathView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_map" />

    </HorizontalScrollView>

</RelativeLayout>

this is my svg map please help me how should i get click event on click of svg path.

Any help would be highly appreciated.

Chirag Patel
  • 437
  • 2
  • 7
  • 22

2 Answers2

3

I found this (RichPath) amazing library which allow me to detect path click

class

 richPathView.setOnPathClickListener { richPath ->
            if (richPath.name != null) {
                when {
                    richPath.name.toLowerCase() == "m" -> {
                        // my task
                    }
                    richPath.name.toLowerCase() == "e" -> {
                        // my task
                    }
            }
      }

XML

<HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:overScrollMode="never"
        android:layout_centerVertical="true">
        <com.richpath.RichPathView
            android:id="@+id/richPathView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            app:vector="@drawable/ic_map" />

</HorizontalScrollView>

don't know this is valid right soluction or not but it's working.

Chirag Patel
  • 437
  • 2
  • 7
  • 22
0

You can't. There is no way to determine which path in a VectorDrawable has been clicked on. At least no easy way.

The only way I know of right now is to load the SVG into a WebView. And then call a method in your Android app from Javascript.

Call Java function from JavaScript over Android WebView

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181