简体   繁体   中英

How to Resize the view in Android using Touch events

I have drawn few concentric circles and now i wish to bring some touch events such that when i can resize(Expand / Shrink) the circles as a whole. Is it possible to do so ?..

This is the view that i have drawn..

// DrawCircles.java

class DrawCircles extends View {

 private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

public DrawCircles(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
}


protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(2);
    mPaint.setColor(0xFF000000);
    int px = getMeasuredWidth() >>1;
    int py = getMeasuredHeight()>>1 ;
    int radius = Math.min(px, py);
    int diff = radius/6;
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFFFFFFF);
    canvas.drawCircle(px, py, radius-2, mPaint);
    radius-=diff;
    mPaint.setColor(0xFF000000);
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFFFFFFF);
    canvas.drawCircle(px, py, radius-2, mPaint);
    radius-=diff;
    mPaint.setColor(0xFF000000);
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFFFFFFF);
    canvas.drawCircle(px, py, radius-2, mPaint);
    radius-=diff;
    mPaint.setColor(0xFF000000);
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFFFFFFF);
    canvas.drawCircle(px, py, radius-2, mPaint);
    radius-=diff;
    mPaint.setColor(0xFF000000);
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFFFFFFF);
    canvas.drawCircle(px, py, radius-2, mPaint);
    radius-=diff;
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(0xFFFF0000);
    canvas.drawCircle(px, py, radius, mPaint);
    radius-=(diff/2);
    mPaint.setColor(0xFFC11B17);
    canvas.drawCircle(px, py, radius, mPaint);
    mPaint.setColor(0xFFCFCFCF);

        super.onDraw(canvas);
}

}

Please let me know, whether it is possible, if so please provide some resources of the same...

Thanks in Advance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM