package com.exaple.day01rikao; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; public class Myview extends View { public Myview(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public Myview(Context context) { super(context); // TODO Auto-generated constructor stub } public Myview(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { Paint pa = new Paint(); Paint pa1 = new Paint(); float wi = canvas.getWidth(); float he = canvas.getHeight(); pa.setColor(Color.BLACK); pa1.setColor(Color.WHITE); canvas.drawColor(Color.WHITE); canvas.drawCircle(wi / 2, he / 2, 60, pa); canvas.drawCircle(wi / 2, he / 2, 55, pa1); canvas.drawText("hhhhhhhhhhhhhh", wi/4, he/4, pa); super.onDraw(canvas); } /* * @Override public boolean onTouchEvent(MotionEvent event) { wi = * event.getX(); he = event.getY(); this.invalidate(); * * return true; } */ }
时间: 2024-10-14 12:07:11