0

enter image description hereI have a custom imagebutton and I only want the custom imagebutton to be clickable. Currently all of the surrounding area of the button is "clickable" and initiates the new activity. I want to minimize this "clickable background" space. How can I do it?

 <ImageButton
    android:id="@+id/start_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@null"
    android:src="@drawable/flashcardbutton" />
compprogjava
  • 169
  • 2
  • 8

5 Answers5

0

I am not sure about this though but just a guess.. is it possible to use :

public void getHitRect(Rect outRect) {
    outRect.set(getLeft()-10, getTop()-10, getRight()-10, getBottom()-10);
}
Bad Wolf
  • 8,206
  • 4
  • 34
  • 44
Sushil
  • 8,250
  • 3
  • 39
  • 71
0

well giving a shot to the API I found that ImageButton has a method with this signature

public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

and AccessibilityNodeInfo class has this method

public void setBoundsInScreen (Rect bounds)

so with this said I think you should achieve what you are trying to do, this in adition to @Sushil answer should make it work.

jac1013
  • 408
  • 3
  • 11
0

Perhaps this may helps:

<ImageButton
    android:id="@+id/start_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@null"
    android:adjustViewBounds="true" <!-- Here is the thing you need -->
    android:src="@drawable/flashcardbutton" />
user2652394
  • 1,686
  • 1
  • 13
  • 15
0

So, I think this was definitely my fault. Even thhough I made the background "transparent" The frame was still bigger than my image. I just had to use photoshop and crop the image. Thank you all!

compprogjava
  • 169
  • 2
  • 8
  • Your issue is that you didn't really need to use an ImageButton, you want to use a regular Button with an image replacing its background. check my answer. – Tonithy Aug 09 '13 at 22:13
0

You don't want to use an ImageButton with your image as the 'src,' you want to use a regular button with your image as the 'background' otherwise it imitates a button with padding and what not even though you nullify the background image...

Use your original image like this:

 <Button
    android:id="@+id/start_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/flashcardbutton" />
Tonithy
  • 2,300
  • 1
  • 20
  • 20