【问题标题】:How to set foreground Image to ImageButton?如何将前景图像设置为 ImageButton?
【发布时间】:2018-05-17 13:38:17
【问题描述】:

我是 Android 应用开发的新手。我想在 API 级别 19 中将前景图像设置为图像按钮。如何执行此操作?

【问题讨论】:

  • Foreground drawable 无法帮助您解决此问题。改用另一个ImageView,把它放在背景img的同一个FrameLayout
  • @TamHuynh 感谢您的编辑。您能分享此示例代码吗?
  • @TamHuynh 我用 ( questionOption1.setBackgroundResource(R.drawable.check) ) 测试过,图片在后台,但我想在前台显示
  • 你可以使用FrameLayout,希望能解决你的问题

标签: android imagebutton android-imagebutton


【解决方案1】:

对于示例代码,将其用于 1 个答案的布局:

<FrameLayout
    android:id="@+id/answer_section"
    android:layout_width="100dp"
    android:layout_height="100dp">

    <ImageView
        android:id="@+id/answer_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/house_img"/>

    <ImageView
        android:id="@+id/answer_check"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/check_img"/>
</FrameLayout>

您为 2 张图片使用 2 个不同的 ImageView,以便它们可以单独工作,例如制作动画、根据条件显示/隐藏...

【讨论】:

  • 非常感谢。我测试过,效果很好。你拯救了我的一天
猜你喜欢
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 1970-01-01
  • 2014-06-23
  • 2021-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多