0

I have an image button shape like a 'star' and i what the clickable area to be only the 'star' but instead of that i have a transparent square clickable area around the 'star', can anyone please tell me how to remove the square bcoz the next 'star' it's close and the square overlaps the first 'star'. thank you so much

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:layout_weight="1"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="190dp"
    android:layout_marginBottom="180dp">

    <ImageButton
        android:id="@+id/star"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:background="@drawable/star"
        />
Daniel
  • 9
  • 9
  • 1
    Possible duplicate of [ImageButton Border Transparancy - How do I remove the square border around round image?](http://stackoverflow.com/questions/5374066/imagebutton-border-transparancy-how-do-i-remove-the-square-border-around-round) – Robin Vinzenz Feb 04 '16 at 22:26
  • no, if i move them apart still i will be able to click 2 dp away from the star and the button reacts – Daniel Feb 04 '16 at 22:42
  • :) thank you, with your answer i solved i o u a pint – Daniel Feb 05 '16 at 01:05
  • you can try this one on this link, a little explenation would be use onTouchListener instead of onclick http://stackoverflow.com/questions/15343266/how-to-prevent-onclick-method-on-transparent-portion-of-a-png-loaded-imageview – Rashid Feb 05 '16 at 01:41

3 Answers3

1

Instead of ImageButton you can user ImageView and make in clicable.

Serafins
  • 1,237
  • 1
  • 17
  • 36
  • done this too, but still i m able to click in the square and the star will start, i m looking for something to take the shape of the star and be clickable. thank you all for the quick answers – Daniel Feb 04 '16 at 22:52
0

Set

android:background=@android:color/transparent

and insert

android:src=@drawable/star

Or just use an ImageView instead, because you can have OnClickListener on both, therefore they could also function as described in your question.

anthonymonori
  • 1,754
  • 14
  • 36
  • done this already and still able to click 2dp away from the star in the square from the button – Daniel Feb 04 '16 at 22:37
0

You can use:

android:background="@null"

in the imageButton tag.

Benoît Latinier
  • 2,062
  • 2
  • 24
  • 36
Prime
  • 3
  • 2