0

I want to define a full screen ImageView like a picture of a room and let's say that picture have a star on the wall that does something.I want to define a transparent button and make that star clickable but only the shape of the star.I readed something on the internet with "hotspots" but I don't really know how to implement them and if would work.

Marian Pavel
  • 2,726
  • 8
  • 29
  • 65

2 Answers2

0
  • ImageView with transparent background, something like:

    <ImageView
       android:id="@+id/img_background"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:src="@drawable/img_background"   
       android:background="@android:color/transparent" />
    
  • ImageButton with icon star

       <ImageButton
           android:id="@+id/img_star"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_centerInParent="true" 
           android:src="@drawable/icon_star"
           android:background="@android:color/transparent" />
    
  • you should have your star icon in transparent background also

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
  • I don't want to use imageView of that star but I want a shape to take form of that star, I don't know something with pixel detection to take that form if would work – Marian Pavel Feb 06 '15 at 11:39
  • look modified answer, you won't see button background but just star – Xcihnegn Feb 06 '15 at 11:43
0

There is no easy way to do this for all cases. In ImageView widget you should test pixel color at touch position and then accept touch and handle it or drop touch event.

Easy way to drop touch event is to set custom OnTouchListener to ImageView and return true if touch coords are out of star shape.

Difficult part is to understand that touch event can be dropped. If you have simple shape, you can use some math to test that coords are outside or inside your shape. Universal way is to draw a view to bitmap and test pixel color. If it is transparent - drop event, if solid - handle.

I dont have code, google, I think you find some )

Community
  • 1
  • 1
Leonidos
  • 10,482
  • 2
  • 28
  • 37