activity_main.xml布局就一个frameLayout,省略掉
MainActivity.java
@OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); //获取帧布局管理器 FrameLayout frameLayout = findVIEwByID(R.ID.frameLayout); frameLayout.addVIEw(new MyVIEw(this));//将自定义view添加到布局管理器中 }
MyVIEw.java
import androID.content.Context;import androID.graphics.Canvas;import androID.graphics.Paint;import androID.graphics.RectF;import androID.vIEw.VIEw;public class MyVIEw extends VIEw { public MyVIEw(Context context) { super(context); } @OverrIDe protected voID onDraw(Canvas canvas) { super.onDraw(canvas); /**绘制AndroID机器人**/ Paint paint = new Paint();//创建一个画笔 paint.setAntiAlias(true);//采用锯齿功能 paint.setcolor(0xFFA4C739);//设置画笔的颜色为绿色 //绘制机器人的头 RectF rectF = new RectF(10,10,100,100);//定义外轮廓矩形 rectF.offset(90,20); canvas.drawArc(rectF,-10,-160,false,paint);//绘制弧形 //绘制眼睛 paint.setcolor(0xFFFFFFFF);//设置画笔为白色 canvas.drawCircle(165,53,4,paint);//绘制圆 canvas.drawCircle(125,53,4,paint);//绘制圆 //绘制天线 paint.setcolor(0xFFA4C739); paint.setstrokeWIDth(2);//设置笔触的宽度 canvas.drawline(110,15, 125,35,paint); canvas.drawline(180,15, 165,35,paint);//绘制线 //绘制身体 canvas.drawRect(100,75, 190,150,paint); RectF rectF_body = new RectF(100,140, 190,160); canvas.drawRoundRect(rectF_body,10, 10,paint);//绘制圆角矩形 //绘制胳膊 RectF rectF_arm = new RectF(75,75, 95,140); canvas.drawRoundRect(rectF_arm,10, 10,paint);//绘制圆角矩形 rectF_arm.offset(120,0); canvas.drawRoundRect(rectF_arm,10,10,paint);//绘制圆角矩形 //绘制腿 RectF rectF_leg = new RectF(115,150, 135,200); canvas.drawRoundRect(rectF_leg,10,10,paint); rectF_leg.offset(40,0); canvas.drawRoundRect(rectF_leg,10,10,paint); }}
效果:
以上是内存溢出为你收集整理的Android学习笔记绘制几何图形全部内容,希望文章能够帮你解决Android学习笔记绘制几何图形所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)