安卓:使用线性渐变作为背景看起来杀鸡取卵 [英] Android: Using linear gradient as background looks banded

查看:144
本文介绍了安卓:使用线性渐变作为背景看起来杀鸡取卵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个线性渐变适用于我的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);
}

这篇关于安卓:使用线性渐变作为背景看起来杀鸡取卵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆