import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; public class Mytest extends View { public Mytest(Context context, AttributeSet set) { super(context,set); } protected void onDraw(Canvas canvas){ super.onDraw(canvas); Paint paint=new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setColor(Color.BLACK); int viewwid=this.getWidth(); int viewhei=this.getHeight(); float line=(float)java.lang.Math.sqrt(viewwid*viewwid-viewwid/2*viewwid/2);//等边三角形中间的直线 float mdwr=(float)(viewwid/2-viewwid/15);//魔动王中间的半径 float mdw=mdwr*3/2;//魔动王中间的直线 float mdwj=(float)java.lang.Math.sqrt(mdw*mdw/3);//直角短边 float mdwc=(float)java.lang.Math.sqrt(mdw*mdw+mdwj*mdwj);//直角长边 // -----------------魔动王---------------------- canvas.drawCircle(viewwid/2,viewhei/2,viewwid/2,paint); canvas.drawCircle(viewwid/2,viewhei/2,viewwid/2-viewwid/15,paint); canvas.drawPoint(viewwid/2,viewhei/2,paint); Path path1=new Path(); path1.moveTo(viewwid/2,viewhei/2-mdwr); path1.lineTo(viewwid/2+mdwj,viewhei/2-mdwr+mdw); path1.lineTo(viewwid/2-mdwj,viewhei/2-mdwr+mdw); path1.lineTo(viewwid/2,viewhei/2-mdwr); canvas.drawPath(path1,paint); Path path2=new Path(); path2.moveTo(viewwid/2,viewhei/2+mdwr); path2.lineTo(viewwid/2-mdwj,viewhei/2+mdwr-mdw); path2.lineTo(viewwid/2+mdwj,viewhei/2+mdwr-mdw); path2.lineTo(viewwid/2,viewhei/2+mdwr); canvas.drawPath(path2,paint); float[] mdwx= { mdwc/3,viewhei/2,mdwc,viewhei/2, viewwid/2-mdwc/6,viewhei/2-mdwr+mdw,viewwid/2+mdwc/6,viewhei/2+mdwr-mdw, viewwid/2+mdwc/6,viewhei/2-mdwr+mdw,viewwid/2-mdwc/6,viewhei/2+mdwr-mdw }; canvas.drawLines(mdwx,paint); } }
08-14
08-14