比较样式1111

<pre name="code" class="java">public class CustomView extends View{
    private String TAG = "CustomView";
    private int mViewHeight;
    private int mViewWidth;
    private Paint mPaint;
    public CustomView(Context context) {
        super(context);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        // TODO Auto-generated method stub
        super.onSizeChanged(w, h, oldw, oldh);
        mViewHeight = h;
        mViewWidth=w;
    }


    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        canvas.translate(mViewWidth/2, mViewHeight/2);

          /*----------------- 1 获取路径路径长度 ------------------------*/
//        Path path = new Path();
//        path.lineTo(0, 200);
//        path.lineTo(200, 200);
//        path.lineTo(200, 0);
//       
//        /**
//         * PathMeasure第二个参数:是否强制关闭,为true时getLength比为false的值小
//         */
//        PathMeasure measure = new PathMeasure(path, false);//600
//        PathMeasure measure2 = new PathMeasure(path, true);//800
//       
//        canvas.drawPath(path, mPaint);

         /*-----------------2 获取下个路径------------------------*/

//        Path path = new Path();
//        //多路径效果需要关闭硬件加速
//        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
//        path.addRect(-300, -300, 300, 300, Path.Direction.CW);
//        PathMeasure measure = new PathMeasure(path, false);
//       
//        //获取下一个路径,有可能获取不到
//        int len1 = (int) measure.getLength();
//        boolean nextPath = measure.nextContour();
//        int len2 = 0;
//        if (nextPath) {
//            len2 = (int) measure.getLength();
//        }
//        Log.i("CustomView", "len1: "+len1+" len2:"+len2);
//       
//        canvas.drawPath(path, mPaint);


        /*-----------------3 截取路径------------------------*/
//        Path path = new Path();
//        //多路径效果需要关闭硬件加速
//        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
//        PathMeasure measure = new PathMeasure(path, false);
//        //获取下一个路径,有可能获取不到
//        int len1 = (int) measure.getLength();
//        Log.i("CustomView", "len1: "+len1);
//        canvas.drawPath(path, mPaint);
//       
//       
//        Path dstPath = new Path();
//        //将截取的路径放到dstPath路径中
//        //startWithMoveTo 是否从上一个起始点开始绘制(是否保持连续性)
//        measure.getSegment(0, 800, dstPath, true);
//        mPaint.setColor(Color.GREEN);
//        canvas.drawPath(dstPath, mPaint);



        /*-----------------4 截取路径------------------------*/
        Path path = new Path();
        //多路径效果需要关闭硬件加速
        path.addCircle(0, 0, 300, Path.Direction.CW);
        PathMeasure measure = new PathMeasure(path, false);
        float[] pos = new float[2];
        float[] tan = new float[2];//tan = y/x
        measure.getPosTan(measure.getLength()/4, pos, tan);

        Log.i(TAG, "pos:"+pos);
        Log.i(TAG, "tan:"+tan);


        canvas.drawPath(path, mPaint);


    }

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值