渐变不适用于Lollipop API 21

问题描述:

这是我在ImageView上应用的gradient.xml。渐变不适用于Lollipop API 21

<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 [我知道,它的丑陋]。

任何帮助将不胜感激。

我有同样的问题。

我将“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> 

我希望这可以帮助你:)