import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class DrawView extends View {
private int mCircleXY;
private float mRadius;
public DrawView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public DrawView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
init(w,h);
}
private void init(int w, int h) {
// TODO Auto-generated method stub
int length = Math.min(w, h);
mCircleXY = length / 2;
mRadius = length * 0.5f / 2;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
//创建画笔
Paint p=new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.WHITE);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(20);
//颜色
paint.setColor(Color.BLACK);
//排列方式
paint.setTextAlign(Paint.Align.CENTER);
// canvas.drawCircle(60, 20, 10, p);
p.setAntiAlias(true);
paint.setAntiAlias(true);
canvas.drawCircle(mCircleXY,mCircleXY,mRadius, p);
canvas.drawText(“我有个盆,我有个苹果,昂,苹果盆”, mCircleXY,mCircleXY, paint);
}
}