带图像的 Button、ImageButton 和可点击的 ImageView 之间的区别?

发布于 2025-01-08 19:18:20 字数 95 浏览 0 评论 0原文

带图像的 ButtonImageButton 和可点击的 ImageView 之间有什么区别吗?

Is there any difference between Button with image, ImageButton and clickable ImageView?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

东风软 2025-01-15 19:18:20

这可能只涵盖了部分差异,实际查看 Android 源代码树以了解到底发生了什么会很有帮助。

ImageButtons 具有推送状态,而可点击图像则没有。
您也不能为 ImageButton 调用 setText,但可以使用常规按钮。

它们都是从视图中派生的,但是查看以下扩展链可能会有所帮助。

java.lang.Object
↳ android.view.View
   ↳ android.widget.ImageView
       ↳ android.widget.ImageButton

相对

java.lang.Object
↳ android.view.View
   ↳ android.widget.TextView
       ↳ android.widget.Button

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.

java.lang.Object
↳ android.view.View
   ↳ android.widget.ImageView
       ↳ android.widget.ImageButton

versus

java.lang.Object
↳ android.view.View
   ↳ android.widget.TextView
       ↳ android.widget.Button
勿挽旧人 2025-01-15 19:18:20

差异可能很微妙。理解这一点最直接的方法是从查看文档开始。如果您查看 Button 文档,您可以看到 Button 派生自 TextView。另一方面 ImageButton 派生自图像视图。因此从根本上来说,Button 可以包含文本并且可以单击,而 ImageButton 在设置图像方面更加灵活。它具有来自其 ImageView 基类的方法,例如 setImageURI,而 Button 则没有。这两者与普通 ImageView 之间的区别之一是,您可以拥有按钮状态,这在 ButtonImageButton 中都有解释。文档。

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 from TextView. ImageButton on the other hand is derived from ImageView. So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not. One of the differences between these two and just a plain ImageView is that you can have button states which is explained in both of the Button and ImageButton docs.

他是夢罘是命 2025-01-15 19:18:20
ImageView = Display Images (android:src)

ImageButton = Diaplay 图像作为 imageViewget click 效果作为按钮 (android:src) 并且无法将文本设置为它。

Button = set text and (android:background)
ImageView = Display Images (android:src)

ImageButton = Diaplay Images as imageView and get click effect as button (android:src) and cannot set text to it.

Button = set text and (android:background)
A君 2025-01-15 19:18:20

前面的答案中没有提到的另一个方面是(例如)列表项视图中的使用。如果您嵌入 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.

油饼 2025-01-15 19:18:20
button instanceof ImageButton == false;
imageButton instanceof Button == false;
button instanceof TextView == true;
imageButton instanceof ImageView == true;
button instanceof ImageButton == false;
imageButton instanceof Button == false;
button instanceof TextView == true;
imageButton instanceof ImageView == true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文