渐变兼容性问题 - ICS默认的颜色比以前的所有Android版本都少

时间:2011-12-26 13:55:35

标签: android android-4.0-ice-cream-sandwich

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

姜饼(2.3.3)模拟器左,ICS(4.0.3)模拟器右。请注意红色框内的渐变淡化效果差异(在单独的窗口中打开以查看完整大小的图像)。

主视图背景:

<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>

导致此问题的原因是什么?如何解决这个问题,以便ICS渐变看起来像2.3.3版本一样平滑?问题是仅在模拟器上发生的吗?

4 个答案:

答案 0 :(得分:1)

我认为问题在于android(右侧)使用较少的颜色绘制渐变。我相信你想要启用抖动来帮助掩盖颜色深度的下降。也许看到这个答案link

我不完全确定它是如何工作的,但我相信android有时会默认为RGB_565模式,即使该设备能够支持24位颜色。

答案 1 :(得分:1)

如果在应用程序中启用了硬件加速,ICS会自动添加渐变效果。 也可以强制所有应用程序进行硬件加速,您会注意到某些应用程序将具有渐变背景,而不是黑色。

答案 2 :(得分:0)

我看到您的评论使用PixelFormat.RGBA_8888没有帮助 您也可以尝试添加抖动标记:window.addFlags(WindowManager.LayoutParams.FLAG_DITHER); 你可以在这里看到我之前关于抖动和颜色的相关答案:
Awful background image quality in Android

答案 3 :(得分:0)

刚刚在ICS 4.0.3设备上验证:这只是模拟器问题