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?
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
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>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.