7

2.3.3 left, ICS on right (emulator). Notice the gradient fade effect difference inside the red box.

Gingerbread (2.3.3) emulator left, ICS (4.0.3) emulator right. Notice the gradient fade effect difference inside the red box (open in separate window to see the full sized image).

Mainview background:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/app_bg"
android:orientation="vertical" >

...

</LinearLayout>

app_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#000" android:centerColor="#333"
    android:endColor="#000" android:angle="270" />
</shape>

What is causing this issue? How to fix this, so that the ICS gradient would look as smooth as the 2.3.3 version? Does the problem occur only on emulator?

Indrek Kõue
  • 6,449
  • 8
  • 37
  • 69

4 Answers4

1

I think the problem is that android is (on the right) drawing the gradient using fewer colours. I believe you want to enable dithering to help disguise the drop in the color depth. Maybe see this answer link

I'm not totally sure how it works, but I believe android will sometimes default to RGB_565 mode, even if the device is capable of 24bit colors.

Community
  • 1
  • 1
Wozza
  • 622
  • 2
  • 9
  • 21
  • Yes, it seems to be somekind of defaulting to fewer number of colors than needed to correctly draw the gradient. But why it happens on ICS and how to change it- I have no idea and I haven't found a solution either. Lets hope someone who knows the answer posts it here... Setting the `window.setFormat(PixelFormat.RGBA_8888); ` in `onAttachedToWindow()` at the activity where the background is drawn is not fixing the problem. – Indrek Kõue Dec 26 '11 at 16:04
1

ICS automaticly adds gradient effect if hardware acceleration is enabled in application. It is also possible to force hardware acceleration for all apps, you will notice that some apps will have gradient background, instead of black.

xmRipper
  • 11
  • 1
0

I saw your comment that using PixelFormat.RGBA_8888 didn't help.
You can also try adding the dither flag: window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);.
You can see my previous related answer about dithering and colours here:
Awful background image quality in Android

Community
  • 1
  • 1
Jave
  • 31,598
  • 14
  • 77
  • 90
  • 1
    I added `getWindow().setFormat(PixelFormat.RGBA_8888);` and `getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);` to my `onCreate` method and it still doesn't fix the problem (doesn't matter if it is before or after `super.onCreate(savedInstanceState);`). – Indrek Kõue Jan 03 '12 at 12:02
  • 1
    Very strange, the only thing I can think causes your problem in that case is if the engine optimizes the drawable too much, if you set the gradient color as #FF000000 instead of just #000, could possibly work, but it sounds like a glitch in ICS. – Jave Jan 03 '12 at 12:30
  • Tried 6 character color codes and 8 character color codes (alpha as FF) but still, the gradient looks like from 90's – Indrek Kõue Jan 03 '12 at 13:03
0

Just verified on ICS 4.0.3 device: this is emulator ONLY problem.

Indrek Kõue
  • 6,449
  • 8
  • 37
  • 69