2010年3月27日土曜日

Android簡単サンプル【弧描画】

【ソース】
package com.naozary.android.example.simple;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;

public class simple extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        setContentView(new GraphicsTestView(this));

    }
}

class GraphicsTestView extends View {
    public GraphicsTestView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(
                Color.argb(
                        255,        // 透明度
                        255,        // Red
                        255,        // Green
                        0            // Blue
                )
        );

        paint.setAntiAlias(true);
        RectF oval1 = new RectF(120.0f, 20.0f, 160.0f, 60.0f);
        canvas.drawArc(oval1, 0, 30, true, paint);
      
        RectF oval2 = new RectF(120.0f, 80.0f, 160.0f, 120.0f);
        canvas.drawArc(oval2, 0, 90, true, paint);
      
        RectF oval3 = new RectF(120.0f, 140.0f, 160.0f, 180.0f);
        canvas.drawArc(oval3, 0, 180, true, paint);
      
        RectF oval4 = new RectF(120.0f, 200.0f, 160.0f, 240.0f);
        canvas.drawArc(oval4, 0, 270, true, paint);

        RectF oval5 = new RectF(120.0f, 260.0f, 160.0f, 300.0f);
        canvas.drawArc(oval5, 90, 270, true, paint);

        RectF oval6 = new RectF(120.0f, 320.0f, 160.0f, 360.0f);
        canvas.drawArc(oval6, 90, 270, false, paint);
      
    }
}

【実行結果】

0 件のコメント:

コメントを投稿