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.BLUE); int viewwid=this.getWidth(); float line=(float)java.lang.Math.sqrt(viewwid*viewwid-viewwid/2*viewwid/2);//等边三角形中间的直线 float[] pts={ viewwid/2,0,viewwid,line,//1 viewwid,line,0,line,//2 0,line,viewwid/2,0,//3 viewwid/2,0,viewwid/2,line,//中线 0,line,viewwid/4*3,line/2,//中线 viewwid,line,viewwid/4,line/2//中线 }; canvas.drawLines(pts,paint); canvas.drawCircle(viewwid/2,line/3*2,line/3,paint);//圆 }}
安卓等边三角形
最新推荐文章于 2021-05-12 17:08:25 发布