【问题标题】:overlaying an image button with another image while selected选择时用另一个图像覆盖一个图像按钮
【发布时间】:2018-04-08 11:00:27
【问题描述】:

我的 ImageButton 包含一个带有透明区域的绘图图像。我有另一个矩形图像(也有透明区域),我想把它放在图像按钮的图像上,所以只要选择了按钮,两者都是可见的。

这是按钮的 XML 代码:

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

谁能帮帮我?

【问题讨论】:

    标签: java android selecteditem android-imagebutton


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      为了在imagebutton叠加 imageview,只需将它们添加到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>
      

      现在为了仅在按下按钮时显示 overlay 图片,只需将 imageview(overlay) 默认设置为 android:visibility="gone",然后使其 visible imagebutton 被点击。

      【讨论】:

        【解决方案3】:

        您可以查看 android 的“选择器”,您可以在其中定义在按钮的不同状态(例如按下等)下显示哪些可绘制对象。

        【讨论】:

          猜你喜欢
          • 2014-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-04
          • 1970-01-01
          相关资源
          最近更新 更多