博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
绘制圆形,在指定空间范围内受限的显示效果;
阅读量:6209 次
发布时间:2019-06-21

本文共 2804 字,大约阅读时间需要 9 分钟。

package com.example.com.skills_utf8;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.graphics.drawable.BitmapDrawable;import android.os.Handler;import android.util.AttributeSet;import android.widget.ProgressBar;import java.util.Timer;import java.util.TimerTask;/** * Created by matengfei on 15/8/10. */public class _64CircleProgress extends ProgressBar{    Paint paint = new Paint();    Paint paint_arc = new Paint();    Paint paint_bitmap = new Paint();    int radius = 100;    int stroke_width = 25;    RectF circle_rect = new RectF();    //Timer timer = new Timer();    Handler handler = new Handler();    int progress = 0;    Bitmap bitmap_pause;    Bitmap bitmap_start;    public _64CircleProgress(Context context, AttributeSet attrs) {        super(context, attrs);        paint.setColor(Color.BLACK);        paint.setStyle(Paint.Style.STROKE);        paint.setStrokeWidth(stroke_width);        paint.setAntiAlias(true);        paint_arc.setColor(Color.YELLOW);        paint_arc.setStyle(Paint.Style.STROKE);        paint_arc.setStrokeWidth(stroke_width);        paint_arc.setAntiAlias(true);        //paint_bitmap        handler.postDelayed(new MyRunnable(), 1000);        // 加载暂停,播放按钮        //BitmapDrawable bitmapdrawable_pause = (BitmapDrawable)getResources().getDrawable(R.drawable.pause_circle, context.getTheme());        //bitmap_pause = bitmapdrawable_pause.getBitmap();        bitmap_pause = BitmapFactory.decodeResource(getResources(), R.drawable.pause_circle);        bitmap_start = BitmapFactory.decodeResource(getResources(), R.drawable.start_circle);    }    @Override    protected synchronized void onDraw(Canvas canvas) {       // super.onDraw(canvas);        if(progress++ >= 360){            progress = 0;        }        circle_rect.set(getWidth() / 2 - radius, getHeight() / 2 - radius, getWidth() / 2 + radius, getHeight() / 2 + radius);        canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, paint);        canvas.drawArc(circle_rect, -90, progress, false, paint_arc);        canvas.drawBitmap(bitmap_pause,                circle_rect.centerX()-bitmap_pause.getWidth()/2,                circle_rect.centerY()-bitmap_pause.getHeight()/2,                paint_bitmap);    }    class States{        public static final int pause = 0;        public static final int start = 1;        public static final int stop = 2;    }    class MyRunnable implements Runnable {        @Override        public void run() {            invalidate();            handler.postDelayed(new MyRunnable(), 100);        }    }}

转载于:https://www.cnblogs.com/sinawear/p/4717964.html

你可能感兴趣的文章
Dom学习笔记
查看>>
Django抛错不存在(DoesNotExist)
查看>>
PHP中的命名空间
查看>>
Django——认证系统(Day72)
查看>>
idea 如何隐藏/展示不想看到的文件
查看>>
JAVA流程控制学习总结
查看>>
配置yum,nc,telnet
查看>>
IOS 应用中从竖屏模式强制转换为横屏模式
查看>>
jvm02
查看>>
jmeter学习笔记(一)
查看>>
MySQL索引背后的数据结构及算法原理-转
查看>>
Oracle11.2.0.4 windows32+64bit opatch工具 11.2.0.0 百度云盘下载
查看>>
Server Develop (三) 多进程实现C/S
查看>>
HBase数据备份及恢复(导入导出)的常用方法
查看>>
1206封装电容在物料可靠性设计比较低
查看>>
调试与分析
查看>>
Nginx 实战(一) 集群环境搭建
查看>>
sqlserver中 事物 索引及视图
查看>>
NOIP2011 铺地毯
查看>>
MySQL学习【第十二篇事务中的锁与隔离级别】
查看>>