android - 渐变不适用于 Lollipop API 21

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

这是我在 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 [我知道,它很丑陋]。

任何帮助将不胜感激。

最佳答案

我遇到过同样的问题。

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

希望对您有所帮助:)

关于android - 渐变不适用于 Lollipop API 21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39861198/

相关文章:

android - 在 android 上使用 Fresco 库显示来自 SD 卡的图像

android - 如何在Android Studio中声明BuildConfig文件?

java - Android - Universal ImageLoader错误必须在使用前进行配置初始化

java - 通过单击菜单项打开特定文件夹

java - ImageView 随着 firebase 适配器不断变化

android - 何时在 Android NavigationDrawer 中为 ImageView 设置 Resource

java - 如何在圆形imageView android上添加阴影和边框?

android - 即使应用程序被用户从后台杀死,如何始终运行后台服务

javascript - 如何在android 5.0( Lollipop )中显示数字键盘

java - 在 Android 中对齐两个 TextView