Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageButton in Android

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> 
like image 934
Nandagopal T Avatar asked Jul 23 '10 13:07

Nandagopal T


People also ask

What is the difference between Button and ImageButton in android?

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.

Can you add text to an ImageButton android?

ImageButton can't have text (or, at least, android:text isn't listed in its attributes).

What is difference between ImageView and ImageButton?

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.

How do I make a clickable image button?

To avoid confusion rename your button android:onClick="onClick" , like android:onClick="imageButtonOnClick" . Thank you!


1 Answers

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...

like image 88
John Feagans Avatar answered Oct 07 '22 22:10

John Feagans