源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android UI效果之绘图篇(四)

  • 时间:2022-07-04 17:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android UI效果之绘图篇(四)
上一篇博文说到了Shader的五个子类 - BitmapShader - LinearGradient - RadialGradient - SweepGradient - ComposeShader 其中BitmapShader和LinearGradient已经做了说明,今天就把剩余的三个Shader补充一下 [b]3. RadialGradient [/b]先看下构造方法
 /**
   @param centerX   中心X坐标
   @param centerY   中心Y坐标
   @param radius   半径
   @param centerColor 开始颜色
   @param edgeColor  结束颜色
   @param tileMode  The Shader tiling mode
   */
  public RadialGradient(float centerX, float centerY, float radius,int centerColor, int edgeColor, @NonNull TileMode tileMode)


 public RadialGradient(float centerX, float centerY, float radius,@NonNull int colors[], @Nullable float stops[], @NonNull TileMode tileMode)

第一个构造方法已经进行了文档说明,比较简单,而第二个构造方法和LinearGradient同理,就不再赘述,使用方法也基本类似,这里直接看下效果即可
RadialGradient rg = new RadialGradient(canvas.getWidth()/2, canvas.getHeight()/2, 200, 0xffff0000, 0xff0000ff, Shader.TileMode.[CLAMP|REPEAT |MIRROR]);
    paint.setShader(rg);
    canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
① CLAMP [img]http://files.jb51.net/file_images/article/201602/2016223154305869.png?2016123154326[/img] ② REPEAT [img]http://files.jb51.net/file_images/article/201602/2016223154350257.png?201612315440[/img] ③ MIRROR [img]http://files.jb51.net/file_images/article/201602/2016223154411945.png?2016123154422[/img] 1、SweepGradient
/**
  *
  * @param cx  中心X坐标
  * @param cy  中心Y坐标
  * @param color0 开始颜色
  * @param color1 结束颜色
  */
 public SweepGradient(float cx, float cy, int color0, int color1)
[img]http://files.jb51.net/file_images/article/201602/2016223154515323.png?2016123154522[/img] 第一个构造方法比较简单,没什么好说的,效果的话类似于做煎饼皮,展开选择360度。主要看第二个构造方法
 public SweepGradient(float cx, float cy,int colors[], float positions[])
cx、cy没什么好说的,中心点坐标,colors颜色数组,主要是positions,positions中每个item的取值范围在0f-1f之间,对于colors中相应颜色在图形中的位置
int[] colors = {0xffff0000, 0xff00ff00, 0xffffff00, 0xffffffff,0xff000000};
float[] positions = {0f,0.25f, 0.5f, 0.75f, 1f};
SweepGradient rg = new SweepGradient(canvas.getWidth() / 2, canvas.getHeight() / 2, colors, positions);
paint.setShader(rg);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
[img]http://files.jb51.net/file_images/article/201602/2016223154620578.png?2016123154629[/img] [b]ComposeShader [/b]
ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode)
ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode)
ComposeShader,混合Shader,看到构造方法,大家应该就已经会用ComposeShader,其实就是对两个shader进行取并集交集操作,遗忘了的同学可以翻看下上一篇文章,这里就不再演示了。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部