Ben
Ben

Reputation: 459

How to force ImageButton To Scale Like ImageView

I have an ImageView that scales down when I set the layout width to fill parent. But when I change it to an ImageButton, it doesn't scale. How do I get the ImageButton to look like the ImageView?

Example

Upvotes: 3

Views: 390

Answers (2)

iutinvg
iutinvg

Reputation: 4205

As Jave suggested, set scaleType to centerCrop. And also set padding to 0dp to take out button borders.

Upvotes: 0

Jave
Jave

Reputation: 31846

Use the android:scaleType attribute (set to center inside or something like that).
However, even if you can get it to scale, I am not sure if you'll get the result you want. The imagebutton displays a regular button, but with an image instead of text, that is you'll get the button-borders around your image. If the imageview works as you want it to, why don't you keep it as an imageview, but set the focusable and clickable attributes on it?

Upvotes: 1

Related Questions