自定义view圆形之生成随机数改变
来源:互联网 发布:c语言加密解密程序 编辑:程序博客网 时间:2024/06/15 09:35
import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import java.util.Random;public class MyView extends View{ private final Paint paint; private final Context context; private int i=1234; public MyView(Context context) { this(context,null); } public MyView(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, 83); //设置内圆半径 int ringWidth = dip2px(context, 5); //设置圆环宽度 //绘制内圆 this.paint.setARGB(155, 167, 190, 206); this.paint.setStrokeWidth(100); 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),200,245,textPaint);// //绘制圆环// this.paint.setARGB(255, 212 ,225, 233);// this.paint.setStrokeWidth(50);// 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(80); 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圆形之生成随机数改变
- 自定义View之点击生成随机数
- 自定义view 生成随机数
- 自定义view圆形进度条,并改变百分比。
- 自定义View---圆形进度条&&点击改变颜色
- 自定义View+点击生成随机数
- 自定义view点击生成随机数
- 自定义View点击生成随机数
- 自定义view之圆形进度条
- 自定义view之圆形ImageView
- 自定义View之圆形TextView
- 自定义view之圆形进度条
- 自定义view之圆形进度条
- 自定义View之简单自定义圆形进度条
- 自定义View之圆形拖动DEMO
- 自定义View之圆形拖动DEMO
- Android自定义View之圆形头像
- 自定义view学习系列之圆形进度条
- 判断字符串为空和null
- telnet连接pop3,IMAP,smtp
- 知识点总结
- 【hadoop Sqoop】Sqoop 1.4.6 安装
- CreateProcess返回740错误码
- 自定义view圆形之生成随机数改变
- POJ 3087 Shuffle'm Up(模拟) (G)
- 选择器
- GCD串行并发队列扫盲
- php 检测远程图片格式 大小
- tftp安装
- Android:最全面的 Webview 详解
- 串口同步操作DEMO
- 数字信封的生成及解析