i have created an image button in my xml
<Button android:layout_height="wrap_content"
android:id="@+id/send"
android:layout_width="50dip"
android:background="@drawable/button_back">
</Button>
and its background like this "button_back.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/back_pressed" /> <!-- pressed png -->
<item android:state_focused="true"
android:drawable="@drawable/back_focused" /> <!-- focused png -->
<item android:drawable="@drawable/back_normal" /> <!-- default png -->
</selector>
its working fine but my problem is that my button width is 50 and my image png width is 70. how can i fit this png to get resized to my button width automatically. Right now no matter what width i give to my button its width gets to the size of image png width.
can someone help me how to do this.
Thanks
try adding to xml button:
android:scaleType="fitCenter"
I believe 9-patch is what you are looking for.
Looks here: http://developer.android.com/guide/developing/tools/draw9patch.html and search for "Nine-patch" here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Update: It might also be a good idea to scale down your images to fit the 50dip width, and use 9-patch for auto-scaling (when orientation changes for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With