0

I have a image button for which I have loaded a image in my XML using android:src tag. I have few questions based on image button :

  1. my image is resized for aspect ratio 130:51 but when I set my image button width and height to wrap_content I see image is loaded as crop I want it to full fit into the image button so that the spacing should not be visible.

  2. when I run the app and tap on the image button I want a feel of state change. But currently I see it looks like a static image and when I tap it really doesn't show the push state changes. To achieve I want to load another image when user does tap event so he can see the state change and feel that button is clicked.

please help me on this.

manlio
  • 18,345
  • 14
  • 76
  • 126
user954299
  • 195
  • 5
  • 15

2 Answers2

1

Try this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed_yellow"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_focused_orange"
          android:state_focused="true" />
    <item android:drawable="@drawable/button_normal_green" />
</selector>

save this XML as any name you want.

and then just set background of button with this XML. so this will change the images as per given states.

Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24
0

1) my_image.setScaleType(ScaleType.FIT_XY);

2)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true"
            android:drawable="@drawable/btn_cab_done_pressed_example" />
        <item android:state_focused="true" android:state_enabled="true"
            android:drawable="@drawable/btn_cab_done_focused_example" />
        <item android:state_enabled="true"
            android:drawable="@drawable/btn_cab_done_default_example" />
    </selector>
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57