自定义控件之放大缩小和移动.进度
来源:互联网 发布:数据字典的作用是什么 编辑:程序博客网 时间:2024/05/24 04:30
public class FirstProgressView extends View { private int width; private int height; private int progress; private int maxProgress = 100; private Paint mPaintBackGround; private Paint mPaintCurrent; private Paint mPaintText; //圆的初始位置 Context context; public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public int getProgress() { return progress; } public void setProgress(int progress) { this.progress = progress; invalidate(); } public int getMaxProgress() { return maxProgress; } public void setMaxProgress(int maxProgress) { this.maxProgress = maxProgress; } public FirstProgressView(Context context) { super(context); } public FirstProgressView(Context context, AttributeSet attrs) { super(context, attrs); mPaintBackGround = new Paint();//新定义一个画笔,用来画背景 mPaintBackGround.setColor(Color.GRAY);//设置画笔颜色 mPaintBackGround.setAntiAlias(true);//设置为true,代表抗锯齿 mPaintCurrent = new Paint();//用于画进度图 mPaintCurrent.setColor(Color.GREEN); mPaintCurrent.setAntiAlias(true); mPaintText = new Paint();//用来画文本的画笔 mPaintText.setColor(Color.BLACK); mPaintText.setAntiAlias(true); mPaintText.setTextAlign(Paint.Align.CENTER);//设置文本排布方式:正中央 mPaintText.setTextSize(50);//设置文本大小,这里为50xp } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //左起:圆心x坐标,圆心y坐标,半径,Paint对象(画笔) canvas.drawCircle(width / 2, height / 2, 200, mPaintBackGround); canvas.drawCircle(width / 2, height / 2, progress * 200f / maxProgress, mPaintCurrent); //左起:文本内容,起始位置x坐标,起始位置y坐标,画笔 canvas.drawText(progress * 100f / maxProgress + "%", width / 2, height / 2, mPaintText); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //该View布局宽 width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); //该View布局高 height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); //设定本View的大小的方法 setMeasuredDimension(width, height); } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: ScaleAnimation scaleAnimation2 = new ScaleAnimation(0.7f, 1.0f, 0.7f, 1.0f, ScaleAnimation.RELATIVE_TO_PARENT, 0.5f, ScaleAnimation.RELATIVE_TO_PARENT, 0.5f); scaleAnimation2.setDuration(5000);// 设置持续时间 startAnimation(scaleAnimation2); break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: // 获取当前触摸点的x,y坐标 width = (int) event.getX(); height = (int) event.getY(); break; }//重新绘制圆 ,控制小球不会被移出屏幕 invalidate(); // 自己处理触摸事件 return true; }
阅读全文
0 0
- 自定义控件之放大缩小和移动.进度
- 自定义View之图片放大、缩小、移动
- 控件移动,放大,缩小,旋转
- c# 窗体上控件如何放大缩小和移动
- Android图片放大缩小自由移动控件
- VB+MapX移动鼠标放大和缩小
- 手指移动和放大缩小imageview
- android中使用Baidu Map遇到的问题之:移动Mapview上的放大缩小控件
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- Android_自定义控件之两圆点之间来回移动加载进度
- android自定义view实现可自由放大缩小和移动的imageView
- TableLayout中的控件放大和缩小
- 自定义图可以放大和缩小
- 【实训】可以移动放大缩小的图片控件
- 【题解】NOIP普及组 洛谷P1020 导弹拦截
- 小解UML中关联、聚合、依赖(简易区分)
- Golang教程:(三)变量
- Oracle开放远程连接
- python对lxml解析html得到的xpath路径去除()、[]得到模式路径
- 自定义控件之放大缩小和移动.进度
- 面向对象
- 在HTML表单中利用JavaScript实现图片上传的前端校验
- LintCode 二叉树中的最大路径和
- Hadoop HA
- log4j配置详解
- hdu 2012 A计划
- css3图片旋转动画
- 计算机网络复习(Ch4运输层)