【问题标题】:Gradient not working for Lollipop API 21渐变不适用于 Lollipop API 21
【发布时间】:2016-10-04 20:28:25
【问题描述】:

这是我在 ImageView 上应用的 gradient.xml。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <gradient
        android:angle="180"
        android:endColor="#BF000000"
        android:startColor="#00000000"/>
</shape>

我确实看过这篇文章 - Android Gradient on Lollipop not working. - API 21,但我的问题是,我没有使用径向渐变。因此,我的 xml 文件中不包括 gradientRadius。

有什么简单的方法可以解决这个问题吗?

如果没有任何效果,我正在考虑创建一个新位图,对其应用渐变,然后将其设置为 ImageView [我知道,它很难看]。

任何帮助将不胜感激。

【问题讨论】:

    标签: android imageview android-5.0-lollipop gradient linear-gradients


    【解决方案1】:

    我也遇到了同样的问题。

    我将“ImageView”插入“FrameLayout”并应用了形状。

    例如

    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:foreground="@drawable/gradient">
         <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </FrameLayout>
    

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-09
      • 2016-06-11
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      相关资源
      最近更新 更多