In my layout, I have some images that are to be the button background (no text). I am confused to how I should go about it. There are a few options to achieve this -
Personally, I prefer the ImageView so I can scale the images appropriately and then set onClickListener.
Am I missing something or are there performance issues with my approach? Pros and Cons of each will help a lot.
Thanks & Regards
R
There's no differences, except default style.
ImageButtons has push states, where as a clickable image does not. You also can't call setText for ImageButton, you can with a regular button. They all derive from view, but looking at the following extends chain may help a little.
You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView. In this task you create a prototype of an app for ordering desserts from a café.
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.
There are a lot of in-depth answers to the question but the 3 main differences in my opinion are
Button
- 3d rendering of a button that has text.ImageButton
- 3d rendeirng of a button but instead of text you are using an image.ImageView
- a flat image.ImageButton and Button have the pressed,selected, focused, unselected states that can convey to the user the different states of the button.
I don't believe there are any performance benefits of using one vs, the other but there are definitely UI and UX reasons to use each one. ImageView I would assume would be good to display just the image. Users won't really know that they can click on the Image.. but with the button counterparts users are trained that they should click on them.
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