Can anybody tell me how to resize the imageButton
to fit the image exactly? This is the code that I tried, but the image is placed at the position that I am locating using android:scaleType
, but I am not able to reduce the size of imageButton
. Please help me out in rectifying this issue. The code that I tried is:
<ImageButton> android:id="@+id/Button01" android:scaleType="fitXY" // i have tried all the values for this attr android:layout_width="wrap_content" android:layout_height="wrap_content" android:cropToPadding="false" android:paddingLeft="10dp" android:src="@drawable/eye"> // this is the image(eye) </ImageButton>
So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not.
ImageButton can't have text (or, at least, android:text isn't listed in its attributes).
ImageButton has the same property as ImageView . Only one feature is extra, which is, images set through ImageButton are clickable, and actions can be attached with them upon clicking. Just like a button, the setOnClickListener() can be used to set an event listener for click event on this.
To avoid confusion rename your button android:onClick="onClick" , like android:onClick="imageButtonOnClick" . Thank you!
android:background="@drawable/eye"
works automatically.
android:src="@drawable/eye"
was what I used with all the problems of resizing the image the the width and height of the button...
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