我想一个线性渐变适用于我的ListView。 这是我绘制了XML的内容:
I'm trying to apply a linear gradient to my ListView. This is the content of my drawable xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#3A3C39"
android:endColor="#181818"
android:angle="270"
/>
<corners android:radius="0dp" />
</shape>
所以我将其应用到我的ListView有:
So I apply it to my ListView with:
android:background="@drawable/shape_background_grey"
它的工作原理,但它看起来很带状的模拟器和实际设备上也
It works but it looks very "banded" on emulator and on a real device too.
有什么办法减少这种行为?
Is there any way to reduce this "behaviour"?
由于罗曼盖伊提示:
listView.getBackground().setDither(true);
解决我的问题。
solves my problem
如果这还不够特别是对于AMOLED和/或华电国际设备试试这个:
If this is not enough especially for AMOLED and/or hdpi devices try this:
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}