【问题标题】:selectableItemBackground and other Drawables disappear when there is an ImageView behindselectableItemBackground 和其他 Drawable 在后面有 ImageView 时消失
【发布时间】:2018-11-20 11:36:03
【问题描述】:

我的View 层次结构如下所示:

<RelativeLayout>
    <ImageView
        android:id="@+id/my_background_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            androd:id="@+id/my_image"
            android:clickable="true"
            android:foreground="?attr/selectableItemBackground" />
    </LinearLayout>
</RelativeLayout>

如果我将图像Drawable 设置为my_background_image,则?attr/selectableItemBackgroundmy_image 上提供的可绘制波纹消失了。不管我使用什么图像,波纹都完全消失了。我还发现任何“前景”Spinner 的背景(包括向下箭头)也会消失。

这是非常奇怪的行为。有谁知道为什么会这样?

编辑:我想补充一点,只要src="..." 不包含在背景中ImageViewsetImageDrawable() 没有被调用,波纹就会出现。

【问题讨论】:

    标签: android android-layout android-view


    【解决方案1】:

    LinearLayout设置透明背景可以解决问题。

    “无边框按钮在最近的背景上绘制其内容。您的按钮可能在其自身和 ImageView 之间没有背景,因此它在 ImageView 下方绘制”来自This Answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多