1

キャンバスを使用してAndroidで逆時計回りの円弧を描く方法は? キャンバスができない場合、ここに解決策はありますか?

4

2 に答える 2

0

このコードを確認してください。

    public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    private static class AnimView extends View {
        private Paint myPaint;
        private Paint myPaint2;
        private Paint myFramePaint;
        private RectF bigOval;
        public TextView value;
        private RectF bigOval2;
        private float myStart;
        private float mySweep;
        private float SWEEP_INC = 3;
        private float SWEEP_INC2 = 5;
        // Use this flag to control the direction of the arc's movement
        private boolean addToCircle = true;

        public AnimView(Context context) {
            super(context);
            init();
        }

        public AnimView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }

        private void init() {
            myPaint = new Paint();

            myPaint.setAntiAlias(true);

            myPaint.setStyle(Paint.Style.STROKE);

            myPaint.setColor(Color.GREEN);

            myPaint.setStrokeWidth(10);

            bigOval = new RectF(40, 10, 280, 250);

            myFramePaint = new Paint();
            myFramePaint.setAntiAlias(true);
            myFramePaint.setColor(Color.WHITE);
        }

        private void drawArcs(Canvas canvas, RectF oval, boolean useCenter,
                Paint paint) {
            canvas.drawRect(oval, myFramePaint);
            canvas.drawArc(oval, myStart, mySweep, false, paint);

        }

        public void setIncrement(float newIncrement) {
            SWEEP_INC = newIncrement;

        }

        @Override
        protected void onDraw(Canvas canvas) {
            drawArcs(canvas, bigOval, true, myPaint);
            value = (TextView) findViewById(R.id.value);
            drawArcs(canvas, bigOval, true, myPaint);
            myStart = -90;
            // If the arc is currently getting bigger, decrease the value of
            // mySweep
            if (addToCircle) {
                mySweep -= SWEEP_INC;
            }
            // If the arc is currently getting smaller, increase the value of
            // mySweep
            else {
                mySweep += SWEEP_INC;
            }
            // If the animation has reached the end, reverse it

            invalidate();
        }
    }
}
于 2013-05-30T04:17:31.867 に答える