继承View
来源:互联网 发布:万宝宝 知乎 编辑:程序博客网 时间:2024/05/29 04:57
package wld.bawei.com.myonemoni2.view;import android.content.Context;import android.content.Intent;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.util.Log;import android.view.View;import wld.bawei.com.myonemoni2.Main2Activity;import wld.bawei.com.myonemoni2.R;/** * Created by 大金鑫 on 2017/12/3. */public class Huayuan extends View implements Runnable { private int neibj=100; private int wkuan=20; private int pro=0; private Paint paintn; private Paint paintw; private Paint paintwz; private String color; public Huayuan(Context context) { this(context,null); } public Huayuan(Context context, @Nullable AttributeSet attrs) { this(context, attrs,0); } public Huayuan(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Huayuan, defStyleAttr, 0); color = ta.getString(R.styleable.Huayuan_col); if(color==null){ color="#33FF00"; } Log.e("color",""+color); init(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int modew = MeasureSpec.getMode(widthMeasureSpec); int modeh = MeasureSpec.getMode(heightMeasureSpec); int sizew = MeasureSpec.getSize(widthMeasureSpec); int sizeh = MeasureSpec.getSize(heightMeasureSpec); int width=0; int heigth=0; switch (modew){ case MeasureSpec.AT_MOST:{ width=neibj*2+wkuan*2; }break; case MeasureSpec.EXACTLY:{ width=sizew; } } switch (modeh){ case MeasureSpec.AT_MOST:{ heigth=neibj*2+wkuan*2; }break; case MeasureSpec.EXACTLY:{ heigth=sizeh; } } setMeasuredDimension(width,heigth); } private void init() { paintn = new Paint(); paintn.setColor(Color.parseColor(color)); paintw = new Paint(); paintw.setColor(Color.parseColor("#3300ff")); paintw.setAntiAlias(true); paintw.setStyle(Paint.Style.STROKE); paintw.setStrokeWidth(wkuan); paintwz = new Paint(); paintwz.setTextSize(35); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Huaneiyuan(canvas); Huawaiyaun(canvas); Huawenzi(canvas); } private void Huawenzi(Canvas canvas) { String str=pro+"%"; Paint.FontMetrics fm = paintw.getFontMetrics(); int ceil = (int) Math.ceil(fm.descent - fm.ascent); int v = (int) paintwz.measureText(str, 0, str.length()); canvas.drawText(str,getWidth()/2-(v/2),getHeight()/2+(ceil/2),paintwz); } private void Huawaiyaun(Canvas canvas) { RectF rectF = new RectF(); rectF.left=getWidth()/2-neibj-wkuan/2; rectF.top=getHeight()/2-neibj-wkuan/2; rectF.right=getWidth()/2+neibj+wkuan/2; rectF.bottom=getHeight()/2+neibj+wkuan/2; canvas.drawArc(rectF,-90,(pro*360)/100,false,paintw); } private void Huaneiyuan(Canvas canvas) { canvas.drawCircle(getWidth()/2,getHeight()/2,neibj,paintn); } @Override public void run() { while (true){ if(pro<100){ pro+=10; try { Thread.sleep(1000); postInvalidate(); } catch (InterruptedException e) { e.printStackTrace(); } } else{ pro=0; Intent intent = new Intent(getContext(), Main2Activity.class); getContext().startActivity(intent); break; } } }}
阅读全文
0 0
- 继承View
- 自定义View继承view
- 自定义View---继承View
- 自定义View,继承View
- 自定义view继承view
- 自定义View-继承系统View
- 自定义view之继承view
- 自定义View之 继承View
- view继承关系
- 继承View自定义控件
- 继承view要用AppCompatXXX
- 自定义view 之 继承
- 自定义控件-继承View
- android view继承关系
- 自定义view继承surfaceview
- android自定义View-继承
- 继承View 自定义开关
- 自定义View继承ViewGroup
- RxJava2.0的使用详解
- SAP FIORI for iOS
- 12.1 省选训练总结
- Android——Fresco、EventBus、GreenDao、Butterknife、Retrofit综合使用
- 02基础命令
- 继承View
- Unity3D启动时卡在项目Loading界面的解决方法
- vim按键说明
- 如何努力才能成为编程高手
- 十二月目标
- Hive的数据模型之桶表
- Java转Python入门之运算与循环
- MongoDB的使用
- 继承ViewGroup