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