简体   繁体   English

Android(eclipse)图像按钮vs背景图像

[英]Android (eclipse) image button vs background image

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" . 我的问题是,我应该使用ImageButton (我认为是一个可以点击的导入图像,或者是带有android:background="@drawable/imageName"的textview)。
Both seem to allow onClick if I'm not mistaken so what's the pros and or one over the other? 如果我没有弄错的话,两者似乎都允许onClick,那么专业人士或者其他人是什么?

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? 另外,forclick for textview是否适用于背景或仅适用于文本?

You can use android:src="@drawable/imageName" 你可以使用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 如果您使用的是TextView那么您的背景可能不太好

From : Difference between a clickable ImageView and ImageButton 来自: 可点击的ImageView和ImageButton之间的差异

There's no differences, except default style. 除默认样式外没有区别。 ImageButton has a non-null background by default. 默认情况下,ImageButton具有非null背景。

Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable. 此外, ImageButton.onSetAlpha()方法始终返回false,scaleType设置为center并且它始终作为focusable膨胀。

Here's ImageButton's default style: 这是ImageButton的默认样式:

 <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. 我认为imagebutton可能更好。 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. 如果您为图像使用背景,则必须编写一个selector.xml来更改单击和取消单击效果。 so, i think imagebutton may be better. 所以,我认为imagebutton可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM