Android空心圆及层叠效果实现代码
程序员文章站
2023-12-13 20:09:52
本文实例为大家分享了android空心圆及层叠效果的具体代码,供大家参考,具体内容如下
package com.bwei.test.zidingyiview2;...
本文实例为大家分享了android空心圆及层叠效果的具体代码,供大家参考,具体内容如下
package com.bwei.test.zidingyiview2; 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 myview extends view { private context mcontext; private paint mpaint; public myview(context context) { super(context); } public myview(context context, attributeset attrs) { super(context, attrs); } public myview(context context, attributeset attrs, int defstyleattr) { super(context, attrs, defstyleattr); this.mcontext = context; } @override protected void ondraw(canvas canvas) { super.ondraw(canvas); // 得到屏幕宽高 float wi = canvas.getwidth() / 2; float he = canvas.getheight() / 2; // 创建第一个画笔 paint pa = new paint(); // 上色 pa.setcolor(color.green); // 显示圆边 pa.setantialias(true); // 设置空心圆环 pa.setstyle(paint.style.stroke); // 设置圆环宽度 pa.setstrokewidth(6); paint pa2 = new paint(); pa2.setcolor(color.blue); pa2.setantialias(true); paint pa3 = new paint(); pa3.setcolor(color.black); pa3.setantialias(true); // 画什么圆 canvas.drawcircle(wi-85, he-85, 80, pa2); canvas.drawcircle(wi, he, 100, pa); canvas.drawcircle(wi+110, he+110, 120, pa3); } }
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.bwei.test.zidingyiview2.mainactivity"> <com.bwei.test.zidingyiview2.myview android:layout_width="wrap_content" android:layout_height="wrap_content"/> </relativelayout>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。