问题
I tried to add a (radial) gradient as background (in Android 4.0), either as background image or programmatically but none of them never works. I can only test it in emulator, but I guess it's the same on a 4.0 device.
These solutions don't work:
- Placing in raw folder. (Disable Android resource / image / png optimization)
- Making a proxy xml with dithering and anti aliasing true, as well as saving opacy of png to 99%. (android:dither="true" does not dither, what's wrong?)
- Overriding onAttachedToWindow (Android: Using linear gradient as background looks banded)
- Moving to hdpi folder (gradient on Gingerbread)
- Making gradient programmatically (http://crazygui.wordpress.com/2010/09/05/high-quality-radial-gradient-in-android/)
I guess I tried some more things but maybe someone has an idea how to build a working gradient as background?
My current code looks like this:
<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>
and 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" />
回答1:
Obviously it's just the emulator. On a real device it looks good.
回答2:
Try this link mate, http://developer.android.com/reference/android/graphics/RadialGradient.html
override on draw function to draw circle using canvas object
来源:https://stackoverflow.com/questions/21985385/android-gradient-never-works-always-banding