android:dither =“true”没有抖动,有什么不对?

时间:2011-01-22 18:58:34

标签: android android-layout

我一直试图让android来抖动活动的背景图片 - 到目前为止还没有成功。我不知道出了什么问题。

这就是我所做的:

我的活动布局的根元素是LinearLayout:

<LinearLayout android:id="@+id/AbsoluteLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="center_horizontal"
android:background="@drawable/background_dither">

我添加@ drawable / background_dither作为背景图片。 我在drawable-hdpi中放了一个XML文件“background_dither.xml”,其中包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/backimg"
android:src="@drawable/background"
android:dither="true"
android:antialias="true" />

引用了drawable-hdpi中的实际图像background.png。包含大颜色渐变的图像确实会显示,但颜色条纹很重。根据我从SDK中学到的知识,可以通过使用/上面的代理图像定义以及指定android:dither =“true”来减轻这种情况。然而,这绝对没有效果。

我错过了什么让抖动工作?

EDIT:已上传sources here

EDIT2:在没有任何建议的方法有助于消除色带之后,在阅读this blog post from Romain Guy之后,我想知道我的PNG背景是否有alpha通道。它没有。添加一个之后,android实际上似乎使用了RGB8888,正如帖子中所述并且条带消失了(也是为2.2)。仍然想知道为什么其他方法不起作用。

EDIT3:必须确保PNG不仅具有alpha通道,而且至少有一个具有alpha值的像素!= FF,否则android构建工具将再次剥离该位图到没有alpha通道的索引调色板。

5 个答案:

答案 0 :(得分:24)

今天也遇到了这个问题并找到并使用了你的解决方案:在photoshop中创建png,透明度设置并且使用alpha至少有一个像素。实际上我所做的是将图层设置为99%的不透明度。不影响颜色或任何东西,让Android编译器单独留下我的png。

答案 1 :(得分:3)

尝试将此行

getWindow().setFormat(PixelFormat.RGBA_8888); 

super.onCreate()之后,看看是否有帮助。

答案 2 :(得分:2)

我也有这个问题,我修复了将九补丁功能应用于背景图像。

希望这个帮助

答案 3 :(得分:0)

很多人都有同样的问题报告说,当XML属性没有时,在Java代码中的drawable资源上设置setDither(true)。在这种情况下,如果您可以在onCreate方法中获得对LinearLayout的引用,请尝试

linearLayout.getBackground()。setDither(真)。

另一种方法是尝试设置不同的像素格式,如下所述:

http://stuffthathappens.com/blog/2010/06/04/android-color-banding/

祝你好运!

答案 4 :(得分:0)

在Android 2.2.1及更低版本中,如果启用了过滤,则会出现导致抖动被禁用的错误。在Android 2.3.3和3.0上,这个问题似乎已修复。我不确定你所启用的抗锯齿是否也是如此。