本文介绍了在不同的设备平滑渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有梯度绘制这我使用的背景和我wan't它,使它看起来尽可能顺利。谷歌搜索,并通过自己的努力后,我想出了以下内容。在Nexus One上,如果只调用setDither(真)渐变依然绑扎,所以你必须设置的PixelFormat这样Window.setFormat(PixelFormat.RGBA_8888)。但在另一边G1不支持RGBA_8888所以称其为使梯度甚至比以前多Window.setFormat(PixelFormat.RGBA_8888)将在设备上无法正常工作不支持它丑陋。

In my app i have gradient as drawable which i am using as background and i wan't it to make it look as smooth as possible. After googling and trying by myself i came up with the following. On nexus one if you call only setDither(true) your gradient is still banding so you have to set PixelFormat like this Window.setFormat(PixelFormat.RGBA_8888). But on the other side G1 does not support RGBA_8888 so calling it make the gradient even uglier than before so Window.setFormat(PixelFormat.RGBA_8888) will not work well on devices that don't support it.

什么是正确的方式顺利我的梯度在其上我的应用程序将运行的所有设备。

What is the correct way smooth my gradient on all devices on which my app will run.

PS:我发现了一些相关的话题

PS: i found some related topics

http://stackoverflow.com/questions/2936803/how-to-draw-a-smooth-dithered-gradient-on-a-canvas-in-android

http://stackoverflow.com/questions/2791045/is-it-possible-to-dither-a-gradient-drawable

推荐答案

您可以使用自定义形状(把它放在/drawable/gradient.xml或类似的东西):

You can use a custom shape (put it in /drawable/gradient.xml or something like that):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#000000"
    android:endColor="#ffffff"
    android:angle="90"/>
</shape>

此方式,将由OS画,它应该是非常光滑。

This way it will be painted by the os and it should be perfectly smooth.

这篇关于在不同的设备平滑渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 05:14