android 动态渐变,Android 动态修改渐变 GradientDrawable

Android 绘图学习

1GradientDrawable 简介

以前的文章写过 Android中渐变实现方式

前面的文章 讲解了如何实现渐变类似LinearGradient,SweepGradient是用于Paint的setShader的,可以通过定义xml的shape,内部利用gradient标签,将shape作为view的背景快速实现渐变。但当我们需要动态修改时,就需要用到GradientDrawable,它和xml方式对应,可以快速生成可以作为view背景的渐变drawable。

构造函数:

两种生成方式:

public GradientDrawable() ;

/**

* Create a new gradient drawable given an orientation and an array

* of colors for the gradient.

*/

public GradientDrawable(Orientation orientation, @ColorInt int[] colors) ;

参数说明:

Orientation:渐变方向,我们知道xml方式的渐变的方向的控制主要利用角度, 渐变的方向 默认为0 从做向右 ,90时从下向上 必须为45的整数倍。

Orientation方向定义如下,很简单就不翻译中文了。

public enum Orientation {

/** draw the gradient from the top to the bottom */

TOP_BOTTOM,

/** d

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值