3

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:

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" />
Community
  • 1
  • 1
Bevor
  • 8,396
  • 15
  • 77
  • 141
  • see http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape – pskink Feb 24 '14 at 11:01
  • It's still banding in this example. Moreover I can't even create a radial gradient because of `java.lang.IllegalArgumentException: radius must be > 0` although I've set a radius (example bottom) – Bevor Feb 24 '14 at 11:17

2 Answers2

2

Obviously it's just the emulator. On a real device it looks good.

Bevor
  • 8,396
  • 15
  • 77
  • 141
0

Try this link mate, http://developer.android.com/reference/android/graphics/RadialGradient.html

override on draw function to draw circle using canvas object

Pulkit Sethi
  • 1,325
  • 1
  • 14
  • 22