Class类探索(一)
来源:互联网 发布:c语言中的贪心算法 编辑:程序博客网 时间:2024/05/21 06:45
感觉阔别scdn已经很久了,一个是项目比较忙,一个是许多想写的东西不敢轻易下笔写,最近又看了一些书,就更没有时间了,前天动手画了个表,贴贴代码,尚未完成,后续更新。
/** * Created by Administrator * draw a clock */public class MyClock extends View { private Paint paintCircle; private Paint paintScale; private Paint paintPointerMinute; private Paint paintPointerHour; public MyClock(Context context) { super(context); init(context); } public MyClock(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(context); } public MyClock(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } public MyClock(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(context); } /** * 外圆;圆心:屏幕中心;半径:屏幕宽的一半 */ private void init(Context context) { /*---------------------*/ DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels; int screenHeight = displayMetrics.heightPixels; LogT.i("屏幕的宽高是:" + screenWidth + ";" + screenHeight); /*---------------------*/ paintCircle = new Paint(); paintCircle.setStyle(Paint.Style.STROKE); paintCircle.setAntiAlias(true); paintCircle.setStrokeWidth(5f); paintCircle.setColor(Color.RED); paintScale = new Paint(); paintScale.setColor(Color.RED); paintScale.setAntiAlias(true); paintScale.setStrokeWidth(3f); paintPointerMinute = new Paint(); paintPointerMinute.setAntiAlias(true); paintPointerMinute.setStrokeWidth(10f); paintPointerMinute.setColor(Color.BLACK); paintPointerHour = new Paint(); paintPointerHour.setAntiAlias(true); paintPointerHour.setStrokeWidth(20f); paintPointerHour.setColor(Color.BLACK); } // TODO: 2017/6/27 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, getMeasuredWidth() / 2, paintCircle); //paint the scale drawScale(canvas); // paint the pointer drawPointer(canvas); } /** * paint the pointer * @param canvas canvas */ private void drawPointer(final Canvas canvas) { canvas.translate(getMeasuredWidth()/2,getMeasuredHeight()/2); canvas.drawLine(0,0,100,100,paintPointerHour); canvas.drawLine(0,0,100,200,paintPointerMinute); canvas.save(); } /** * paint the scale * @param canvas canvas */ private void drawScale(Canvas canvas) { for (int i = 1;i<=12;i++) { //翻转画布 canvas.rotate(30,getMeasuredWidth()/2,getMeasuredHeight()/2); if (i ==3||i == 6|| i ==9||i == 12) { paintScale.setStrokeWidth(5f); paintScale.setTextSize(30f); canvas.drawLine(getMeasuredWidth()/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2, getMeasuredWidth()/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2+50, paintScale); String s = String.valueOf(i); canvas.drawText(s,(getMeasuredWidth()-paintScale.measureText(s))/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2+100, paintScale); }else { paintScale.setStrokeWidth(3f); paintScale.setTextSize(20f); canvas.drawLine(getMeasuredWidth()/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2, getMeasuredWidth()/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2+30, paintScale); String s = String.valueOf(i); canvas.drawText(s,(getMeasuredWidth()-paintScale.measureText(s))/2, (getMeasuredHeight()-Math.min(getMeasuredWidth(),getMeasuredHeight()))/2+80, paintScale); } } }}
阅读全文
0 0
- Class类探索(一)
- Class类探索(一)
- lua中面向对象(class)实现探索(一)
- lua中面向对象(class)实现探索(一)
- 探索 Word 2007 开发 II(一):引用 .NET Framework Class Library 在线文档 - Allen Lee
- 探索 Word 2007 开发 II(一):引用 .NET Framework Class Library 在线文档
- 软件探索(一)
- 数据探索(一)
- HyBrid探索(一)
- 反射(一)---类Class
- 对Class类的几点探索
- 探索软件设计模式(一)
- 百度贴吧发贴机探索(一)
- 探索软件设计模式(一)
- 探索软件设计模式(一)
- [原创] Delphi(一) --探索
- 探索之路(一)
- Django 探索(一) HelloWorld
- CodeVS 1295 N皇后问题 题解
- about memory leak
- 目标检测的图像特征提取——Haar特征
- 关于ActionBarActivity引发的jar包只有class没有.Java问题
- 关于fontawesome-webfont93e3.ttf加载不到的解决办法
- Class类探索(一)
- webview调本地相册上传图片
- ssm--之web.xml
- zjoj_4551_Even separation
- 特基础特基础的东西随便写写
- MFC + Opencv 下面调用HoughCircles 报错
- arm-linux-gcc-4.4.3交叉编译python2.7.3并移植到ARM
- 安卓开发进阶之弹性布局FlexboxLayout--Part2(翻译)
- centOS7.0上安装使用zookeeper环境