【问题标题】:Android ImageButton - How to hide the image while showing the background?Android ImageButton - 如何在显示背景的同时隐藏图像?
【发布时间】:2014-11-16 10:06:24
【问题描述】:

我已经阅读了 API 并在 Google 上搜索过,但也许我错过了一些东西:ImageButton 上的所有可见性选项似乎都在谈论这个视图作为一个整体。那么,如果我想隐藏图像但保留背景(除非明确将图像设置为透明的东西),我该怎么办?我正在做一个配对游戏,当单击元素时它应该显示图像,如果下一次单击不匹配图像应该被隐藏,但按钮的灰色背景应该保留。

谢谢!

【问题讨论】:

    标签: android android-layout android-view visibility imagebutton


    【解决方案1】:

    那么,如果我想隐藏图片该怎么办

    尝试将其设置为@null 或在您的drawables 中创建透明PNG 并设置它。

    【讨论】:

      【解决方案2】:

      在 XML 中,删除 android:src="something" 并在代码中删除 imgbtn.setImageBitmap(null);

      【讨论】:

        【解决方案3】:

        除了使用 ImageButton 之外,您还可以在 ImageView 上使用 FrameLayout。将 FrameLayout 的背景设置为灰色,然后根据您的要求显示/隐藏此 FrameLayout/Image。对每个进行相对布局并使其可点击。在此布局的点击事件上,根据需要进行更改。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-24
          • 1970-01-01
          • 1970-01-01
          • 2014-08-07
          • 1970-01-01
          • 2016-05-29
          相关资源
          最近更新 更多