关闭

画点point

标签: Androidpoint
176人阅读 评论(0) 收藏 举报
分类:
package com.example.xfermodesdemo;

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 DrawPointActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {
		private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

		public SampleView(Context context) {
			super(context);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = mPaint;
			canvas.translate(10, 10);
			canvas.drawColor(Color.WHITE);

			float[] pts = new float[] { 10, 20, 30, 40, 50, 60, 70, 80 };
			// (10,20),(30,40),(50,60),(70,80)

			paint.setColor(Color.RED);
			paint.setStrokeWidth(3);
			canvas.drawPoints(pts, paint);// 绘制四个点

			paint.setColor(Color.BLUE);
			paint.setStrokeWidth(0);
			canvas.drawLines(pts, paint);// 绘制两条线 line1 (10,20),(30,40);line2
											// (50,60),(70,80)
		}
	}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:47866次
    • 积分:1604
    • 等级:
    • 排名:千里之外
    • 原创:113篇
    • 转载:36篇
    • 译文:0篇
    • 评论:1条