Source code introduction: Imitate WeChat radar scanning, imitate Android WeChat, cloud broadcast radar scanning animation effect. Click the black circle in the middle to start the scanning animation, and click again to reset. Friends who need this effect can download it and have a look. Source code effect: Source code snippet: - package com.example.tz_demo_8_7;
-
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Matrix;
- import android.graphics.Paint;
- import android.graphics.Paint.Style;
- import android.graphics.Shader;
- import android.graphics.SweepGradient;
- import android.os.Handler;
- import android.util.AttributeSet;
- import android.widget.FrameLayout;
-
- public class MyRadarView extends FrameLayout {
-
- private Paint mPaintNormal;
- private Paint mPaintCircle;
- private int w,h;
- private Matrix matrix;
- private Handler handler= new Handler();
- private int start;
- private Runnable r= new Runnable() {
-
- @Override
- public void run() {
-
- start=start+ 2 ;
- matrix= new Matrix();
- matrix.postRotate(start, w/ 2 , h/ 2 );
- MyRadarView. this .invalidate();
- handler.postDelayed(r, 20 );
- }
- };
-
-
- public MyRadarView(Context context, AttributeSet attrs) {
- super (context, attrs);
-
- initPaint();
- setBackgroundResource(R.drawable.bg);
-
- this .w=context.getResources().getDisplayMetrics().widthPixels;
- this .h=context.getResources().getDisplayMetrics().heightPixels;
- handler.post(r);
- }
-
-
-
- private void initPaint() {
- mPaintNormal = new Paint();
- mPaintNormal.setColor(Color.parseColor( "#A1A1A1" ));
- mPaintNormal.setStrokeWidth( 3 );
- mPaintNormal.setAntiAlias( true );
- mPaintNormal.setStyle(Style.STROKE);
-
-
- mPaintCircle= new Paint();
- mPaintCircle.setColor( 0x9D00ff00 );
- mPaintCircle.setAntiAlias( true );
- }
-
-
-
-
- @Override
- protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec) {
-
- setMeasuredDimension(w, h);
- }
-
-
-
-
- @Override
- protected void onDraw(Canvas canvas) {
-
- canvas.drawCircle(w/ 2 , h/ 2 , w/ 6 , mPaintNormal);
- canvas.drawCircle(w/ 2 , h/ 2 , 2 *w/ 6 , mPaintNormal);
- canvas.drawCircle(w/ 2 , h/ 2 , 11 *w/ 20 , mPaintNormal);
- canvas.drawCircle(w/ 2 , h/ 2 , 7 *h/ 16 , mPaintNormal);
-
-
- Shader shader= new SweepGradient(w/ 2 , h/ 2 , Color.TRANSPARENT, Color.parseColor( "#AAAAAAAAA" ));
- mPaintCircle.setShader(shader);
- canvas.concat(matrix);
- canvas.drawCircle(w/ 2 , h/ 2 , 7 *h/ 16 , mPaintCircle);
-
- super .onDraw(canvas);
- }
- }
Download address: http://download..com/data/2096545 |