首页 > 解决方案 > 如何将前景图像设置为 ImageButton?

问题描述

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

在此处输入图像描述

标签: androidimagebuttonandroid-imagebutton

解决方案


对于示例代码,将其用于 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的图像,以便它们可以单独工作,例如制作动画、显示/隐藏条件......


推荐阅读