Drawable / GradientDrawable 等 相关api

一 Drawable setBounds()

     注: Drawable.setBounds(int left,int top,int right,int bottom);    四边   永远平行坐标系x   y

     参数一  left  为矩形左侧距离y坐标系的距离   top为矩形区域上方距离x坐标系的距离   right 为  右侧 y坐标系距离的距离

                   bottom 为矩形下方距离x坐标系的距离 

     方法 1:gradientDrawable.setBounds(RectF r);   传入矩形区域

     方法2 :Drawable.setBounds(int left,int top,int right,int bottom);  传入上下左右坐标点  形成矩形区域

     作用:这个四参数 或 RectF   指的是drawable将在被绘制在canvas的哪个矩形区域内。

     例子:

 @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = canvas.getWidth();
        int height = canvas.getHeight();
        canvas.translate(400, 400);
        // 绘制坐标线
        mPaint.setColor(Color.RED);
        canvas.drawLine(0, 0, width, 0, mPaint);
        //绘制蓝色Y轴
        mPaint.setColor(Color.BLUE);
        canvas.drawLine(0, 0, 0, height, mPaint);
        canvas.translate(0,10);
        mPaint.setColor(Color.RED);
        canvas.drawLine(0,0,100,0,mPaint);

        // 设置gradientDrawable将被绘制在哪个矩形区域内
        gradientDrawable.setBounds(10, 10, 100, 100);
        gradientDrawable.draw(canvas);
    }

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值