Search code examples
androidkotlinsvgandroid-imageviewandroid-vectordrawable

How to get VectorDrawable path click listener event from imageview in kotlin


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.


Solution

  • 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.