标签:
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); } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.example.com.skills_utf8._64CircleProgress android:id="@+id/progress_cicle" android:layout_width="200dp" android:layout_height="200dp" android:background="@null" /> </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/sinawear/p/4717964.html