Android图形处理-百变Paint

Android图形处理-百变Paint

Paint的基本属性

Android图形处理-Canvas已经有了基本的使用,但是这节介绍几个好玩的属性

设置阴影和渐变

设置渐变

主要是给画笔(Paint)设置一个Shader

sp161108_143636

        Paint paint = new Paint();
        LinearGradient linearShader = new LinearGradient(0, 0, 100, 100,
                new int[]{Color.RED, Color.BLACK, Color.BLUE, Color.DKGRAY},
                null, Shader.TileMode.CLAMP);
        paint.setShader(linearShader);
        canvas.drawCircle(100,100,100,paint);

LinearGradient是Shader的子类。其他子类:

sp161108_142705

LinearGradient构造方法的含义:

    /** Create a shader that draws a linear gradient along a line.
        @param x0           The x-coordinate for the start of the gradient line
        @param y0           The y-coordinate for the start of the gradient line
        @param x1           The x-coordinate for the end of the gradient line
        @param y1           The y-coordinate for the end of the gradient line
        @param  colors      The colors to be distributed along the gradient line
        @param  positions   May be null. The relative positions [0..1] of
                            each corresponding color in the colors array. If this is null,
                            the the colors are distributed evenly along the gradient line.
        @param  tile        The Shader tiling mode
    */

前两个参数是开始点,接下来是结束点,colors是颜色的数组,positions是分布的模式,tile是渐变的模式比如可重复等

设置阴影
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值