我尝试添加(径向)渐变作为背景(在 Android 4.0 中),作为背景图像或以编程方式添加,但它们都不起作用。我只能在模拟器中测试它,但我猜它在 4.0 设备上是一样的。
这些解决方案不起作用:
- 放置在原始文件夹中。 ( Disable Android resource / image / png optimization )
- 使代理 xml 具有抖动和抗锯齿功能,并将 png 的不透明度降低到 99%。 ( android:dither="true" does not dither, what's wrong? )
- 覆盖 onAttachedToWindow ( Android: Using linear gradient as background looks banded )
- 移动到 hdpi 文件夹 ( gradient on Gingerbread )
- 以编程方式制作渐变 ( http://crazygui.wordpress.com/2010/09/05/high-quality-radial-gradient-in-android/ )
我想我尝试了更多的东西,但也许有人知道如何构建一个工作渐变作为背景?
我当前的代码如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashScreen">
<ImageView
android:id="@+id/imageViewLogo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/desc_string"
android:scaleType="centerCrop"
android:src="@drawable/background_image" />
</RelativeLayout>
和 background_image.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background_image"
android:antialias="true"
android:dither="true"
android:src="@drawable/bg_portrait" />
最佳答案
显然这只是模拟器。在真实设备上看起来不错。
关于Android 渐变从不工作(总是带状),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21985385/