带图像的 Button、ImageButton 和可点击的 ImageView 之间的区别?
带图像的 Button
、ImageButton
和可点击的 ImageView
之间有什么区别吗?
Is there any difference between Button
with image, ImageButton
and clickable ImageView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能只涵盖了部分差异,实际查看 Android 源代码树以了解到底发生了什么会很有帮助。
ImageButtons 具有推送状态,而可点击图像则没有。
您也不能为 ImageButton 调用 setText,但可以使用常规按钮。
它们都是从视图中派生的,但是查看以下扩展链可能会有所帮助。
相对
This probably only covers part of the differences, it would be helpful to actually look at the Android Source tree to see exactly what's going on.
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.
versus
差异可能很微妙。理解这一点最直接的方法是从查看文档开始。如果您查看 Button 文档,您可以看到
Button
派生自TextView
。另一方面ImageButton
派生自图像视图。因此从根本上来说,Button
可以包含文本并且可以单击,而ImageButton
在设置图像方面更加灵活。它具有来自其ImageView
基类的方法,例如setImageURI
,而Button
则没有。这两者与普通ImageView
之间的区别之一是,您可以拥有按钮状态,这在Button
和ImageButton
中都有解释。文档。The differences can be subtle. The most direct way to understanding this is to start with looking at the docs. If you look at the docs for Button you can see that
Button
is derived fromTextView
.ImageButton
on the other hand is derived fromImageView
. So fundamentally, aButton
can have text and is clickable, whereas anImageButton
is a bit more flexible in how you set the image. It has methods from itsImageView
base class likesetImageURI
which aButton
does not. One of the differences between these two and just a plainImageView
is that you can have button states which is explained in both of theButton
andImageButton
docs.ImageButton = Diaplay
图像作为imageView
和get click
效果作为按钮(android:src)
并且无法将文本设置为它。ImageButton = Diaplay
Images asimageView
andget click
effect as button(android:src)
and cannot set text to it.前面的答案中没有提到的另一个方面是(例如)列表项视图中的使用。如果您嵌入 Button 或 ImageButton,则列表项的其余部分将不会接收触摸事件。但如果你使用ImageView,那就会了。
One other aspect not mentioned in the previous answers is the usage within (for instance) a list item view. If you an embed a Button or ImageButton, the rest of the list item will not receive touch events. But if you use ImageView, it will.