Android-如何绘制2向渐变? [英] Android - how to draw 2-directional gradient?

查看:111
本文介绍了Android-如何绘制2向渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始玩渐变,我发现绘制1向渐变非常容易(例如从上到下,从左到右或对角线...),但是如何绘制2向渐变呢?我的意思是这样的:

I started playing with gradients and I've found it's pretty easy to draw 1-directional gradient (like from top to bottom, from left to right, or in diagonale...) but how to draw 2-directional gradient? I mean something like this:

蓝色的大矩形是2向渐变的-在右上角是蓝色,在左边是蓝色,在下面是黑色.怎么画呢?

Big blue rectangle it's 2-directional gradient - on top right corner there is blue and to the left its transforming to white and to the bottom it's transforming to the black. How to draw this?

推荐答案

答案是:您必须组合两个不同的LinearGradients,例如:

Answer is: you must combine 2 different LinearGradients, for example:

LinearGradient val = new LinearGradient(0, 0, 0, height, Color.WHITE, Color.BLACK, TileMode.CLAMP);
                LinearGradient sat = new LinearGradient(0, 0, width, 0, Color.WHITE, Color.HSVToColor(hsvCopy), TileMode.CLAMP);
                ComposeShader merged = new ComposeShader(val, sat, PorterDuff.Mode.MULTIPLY)

;

当然很重要:

[view with this background].setLayerType(View.LAYER_TYPE_SOFTWARE, null);

在Android 3.0及更高版本的手机上

on phones with 3.0 android and higher

这篇关于Android-如何绘制2向渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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