1

I'm trying to figure out which is best to use.

I'm trying to develop a simple game and designing the starting activity. to start the game I plan to have a start button.
I want to use a custom design though.

My question is, should I use an ImageButton (which I believe is an imported image that you can click on, or a textview with android:background="@drawable/imageName".
Both seem to allow onClick if I'm not mistaken so what's the pros and or one over the other?

Hope this isn't duplicate question, all I found was info on how to upload images which I don't need. Just need to know advantages to using one versus the other.

also, Does onclick for textview apply to background or only text?

kds
  • 28,155
  • 9
  • 38
  • 55
cjayem13
  • 903
  • 10
  • 24

3 Answers3

1

You can use android:src="@drawable/imageName"

So that the image will be perfect fit. Also you can use

  android:scaleType="fitCenter"
android:adjustViewBounds="true"

If you are using TextView then your background may not be good

Ameer
  • 2,709
  • 1
  • 28
  • 44
1

From : Difference between a clickable ImageView and ImageButton

There's no differences, except default style. ImageButton has a non-null background by default.

Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable.

Here's ImageButton's default style:

 <style name="Widget.ImageButton">
     <item name="android:focusable">true</item>
     <item name="android:clickable">true</item>
     <item name="android:scaleType">center</item>
     <item name="android:background">@android:drawable/btn_default</item>
 </style>
Community
  • 1
  • 1
Shivam Verma
  • 7,973
  • 3
  • 26
  • 34
1

I think imagebutton maybe better. because you must have a click effect for feedback . if you use background for the image ,you have to write a selector.xml for change the click and unclick effects. so, i think imagebutton may be better.

cowboi-peng
  • 777
  • 2
  • 6
  • 24
  • I think I see what you mean. I put both into a fragmentactivity and the text highlights when hover and image only on click. I didn't think of that. Thanks! – cjayem13 Jun 26 '14 at 11:12