android_画图3 画笔的复制以及更新

      接着继续android的画图,源代码就不写 只写部分
private Paint[] mPaints;
mPaints = new Paint[4];
mPaints[0] = new Paint();
            mPaints[0].setAntiAlias(true);
            mPaints[0].setStyle(Paint.Style.FILL);
            mPaints[0].setColor(0x88FF0000);

mPaints[1] = new Paint(mPaints[0]);
            mPaints[1].setColor(0x8800FF00);
mPaints[1]复制了mPaints[0]的特点,只是颜色变了,这就是 创建一个新对象时复制的用处,在adnroid中到处有复制的影子。其实复制就是一种继承吧,父类和子类。

mPaints[2].setStyle(Paint.Style.STROKE);  设置画笔的样式有三种
默认的为Paint.Style.FILL,就是实心的。Paint.Style.STROKE只是外层的线,我是这么理解的。
mPaints[2].setStrokeWidth(4); 画笔的粗细吧,默认的是0,只是一条硬线

@Override protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.WHITE);
         
            drawArcs(canvas, mBigOval, mUseCenters[mBigIndex],mPaints[mBigIndex]);
           
            for (int i = 0; i < 4; i++) {
              //  drawArcs(canvas, mOvals[i], mUseCenters[i], mPaints[i]);
            drawArcs(canvas, mOvals[i], true, mPaints[i]);
            }
            mSweep += SWEEP_INC;
            if (mSweep > 360) {
                mSweep -= 360;
                mStart += START_INC;
                if (mStart >= 360) {
                    mStart -= 360;
                }
                mBigIndex = (mBigIndex + 1) % mOvals.length;
            }
         
           invalidate();
        }

最后注意的是 要想一直画圆 不要忘记invalidate(); 他在不断的更新我是这么理解的
这个地方还不是很透彻。

你可能感兴趣的:(android,360)