自定义圆环随机数
来源:互联网 发布:mysql update 性能 编辑:程序博客网 时间:2024/05/22 14:03
main布局(自定义view控件)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.a_zidingiyiview_demo.RingView android:layout_width="match_parent" android:layout_height="match_parent"></com.example.a_zidingiyiview_demo.RingView></LinearLayout>
自定义view代码
public class RingView extends View { private final Paint paint; private final Context context; private int i=1234; public RingView(Context context) { this(context,null); } public RingView(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; this.paint = new Paint(); this.paint.setAntiAlias(true); //消除锯齿 this.paint.setStyle(Paint.Style.STROKE); //绘制空心圆 } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub int center = getWidth()/2; int innerCircle = dip2px(context, 40); //设置内圆半径 int ringWidth = dip2px(context, 5); //设置圆环宽度 //绘制内圆 this.paint.setARGB(155, 167, 190, 206); this.paint.setStrokeWidth(30); this.paint.setColor(Color.YELLOW); canvas.drawCircle(center,center, innerCircle, this.paint); //绘制文字 Paint textPaint = new Paint(); textPaint.setColor(Color.BLACK); textPaint.setStyle(Paint.Style.FILL); textPaint.setTextSize(25); canvas.drawText(String.valueOf(i),330,370,textPaint); //绘制圆环 /* this.paint.setARGB(255, 212 ,225, 233); this.paint.setStrokeWidth(2); this.paint.setColor(Color.BLUE); canvas.drawCircle(center,center, innerCircle+1+ringWidth/2, this.paint); //绘制外圆 /* this.paint.setARGB(155, 167, 190, 206); this.paint.setStrokeWidth(10); this.paint.setColor(Color.RED); canvas.drawCircle(center,center, innerCircle+ringWidth, this.paint);*/ super.onDraw(canvas); } /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: //随机数的工具 Random random = new Random(); //做计算 i=1001+(int)(Math.random()*1000);// count++; invalidate(); break; } return super.onTouchEvent(event); }}如有雷同 不胜荣幸!!!
阅读全文
0 0
- 自定义圆环随机数
- 自定义圆环
- 自定义圆环
- 自定义圆环样式
- 圆环百分比自定义View
- 自定义圆环1
- 简单自定义圆环
- 自定义进度圆环
- 自定义圆环进度
- android 自定义圆环
- 自定义圆环进度条
- 自定义圆环进度条
- 自定义view-圆环
- 自定义View圆环
- 自定义PointerProgressBar--圆环进度条
- 自定义View圆环进度条
- Android 自定义数字圆环
- 自定义view圆环进度条
- 《程序员的自我修养--链接、装载与库》笔记--第一章温故而知新
- 漏洞银行/逆向工程学习日记(3)-内存寻址方式
- Java并发包源码学习之线程池(一)ThreadPoolExecutor源码分析
- C++通过cin.get()输入字符串
- 使用树莓派3B开启WIFI热点
- 自定义圆环随机数
- 实验吧简单的sql注入--三题答案一样--_--
- 有关Array, ArrayList, LinkedList, Vector的学习笔记
- 1001.害死人不偿命的3n+1的猜想(模拟)
- Apache2.4+Tomcat9.0配置反向代理
- 深度学习之用神经网络进行监督学习
- GitHub 上最火的开源项目 —— Java 篇
- UVA11624 Fire! —— BFS
- jdbc查询的工具类