本文介绍了是否可以抖动渐变可绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下可绘制对象:

I'm using the following drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >

    <gradient
        android:startColor="@color/content_background_gradient_start"
        android:endColor="@color/content_background_gradient_end"
        android:angle="270"
        />

</shape>

问题是我在 hdpi 设备(如 Nexus One 和 Droid)上出现严重条带,因为渐变是从屏幕顶部到最底部.

The problem is that I get severe banding on hdpi devices (like the Nexus One and Droid) since the gradient goes from the top of the screen to the very bottom.

根据http://idunnolol.com/android/drawables.html#shape_gradient 渐变没有抖动"属性.我可以做些什么来平滑渐变?

According to http://idunnolol.com/android/drawables.html#shape_gradient there isn't a "dither" attribute for a gradient. Is there anything I can do to smooth the gradient?

注意:向形状添加 dither="true" 似乎不起作用.

Note: adding dither="true" to shape doesn't seem to work.

推荐答案

我编写了您引用的文档.我又看了一遍代码,不幸的是,除了通过在代码中显式调用 GradientDrawable.setDither() 之外,无法在 GradientDrawable 上启用抖动.

I wrote the documentation you referenced. I've taken another look at the code and unfortunately there's no way to enable dithering on a GradientDrawable except by explicitly calling GradientDrawable.setDither() in code.

(代码的外观,技术上,您可以将 Gradient 作为 only 子元素包含在内,并启用在整个选择器上抖动;然而,这绝对是一个黑客.)

(The way the codes looks, technically you could include the Gradient as the only child of a <selector>, and enable dithering on the entire selector; however, it's definitely a hack.)

我不相信启用抖动会真正解决您的问题,因为抖动(至少正如官方 Android 文档中指出的那样)用于在设备的调色板太小时解决条带问题.由于梯度的大小,这似乎是条带问题.

I'm not convinced enabling dithering will actually solve your problem, as dithering (at least as it's noted in the official Android docs) are for solving banding problems when the device has too small of a color palette. This seems to be a banding problem due to the size of the gradient.

这篇关于是否可以抖动渐变可绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:24