在选择时将图像按钮与另一个图像重叠

时间:2018-04-08 11:00:27

标签: java android selecteditem android-imagebutton

我的ImageButton包含一个图形,周围有透明区域。我有另一个矩形图像(它有透明区域),我希望它放在图像按钮的图像上,所以只要按钮被选中,两者都是可见的。

这是Button的XML代码:

<ImageButton
        android:id="@+id/buttonNormal"
        android:background="@android:color/transparent"
        android:onClick="normal"
        android:src="@drawable/ic_1"
        tools:clickable="true" />

有人能帮帮我吗?

3 个答案:

答案 0 :(得分:0)

您可以尝试在网站上提供浮动自定义按钮(Android Arsenal)。浮动按钮具有覆盖的属性。

答案 1 :(得分:0)

为了{{1>}覆盖imageview <{1}},只需将imagebutton添加到relativelayout中(将它们叠加在一起)。例如,

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:id="@+id/buttonNormal"
        android:background="@android:color/transparent"
        android:onClick="normal"
        android:src="@drawable/first_image"
        tools:clickable="true" />
    <ImageView
        android:src="@drawable/overlay_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

现在为了仅在按下按钮时显示叠加图像,默认情况下只需将图片视图(叠加)设为android:visibility="gone",然后将其设为可见点击imagebutton时。

答案 2 :(得分:0)

您可以查看&#34;选择器&#34;对于android,你可以定义哪个drawable在按钮的不同状态下显示,如按下等。