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.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
                        255            // Blue
                )
        );
        canvas.drawLine(0, 0, 30, 30, paint);
      
        float[] pts     = {    // 点のデータ
                60,    60,        // 1番目の線-始点X,y              
                60,    80,        // 1番目の線-終点X,y
                60 ,80,        // 2番目の線-始点X,y
                100,80,        // 2番目の線-終点X,y
                100 ,80,    // 3番目の線-始点X,y
                100,100        // 3番目の線-終点X,y
        };
        canvas.drawLines(pts, paint);
      
    }
}

【実行結果】

0 件のコメント:

コメントを投稿