Imitation WeChat radar scanning

Imitation WeChat radar scanning

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:

  1. package com.example.tz_demo_8_7;
  2.   
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.graphics.Color;
  6. import android.graphics.Matrix;
  7. import android.graphics.Paint;
  8. import android.graphics.Paint.Style;
  9. import android.graphics.Shader;
  10. import android.graphics.SweepGradient;
  11. import android.os.Handler;
  12. import android.util.AttributeSet;
  13. import android.widget.FrameLayout;
  14.   
  15. public   class MyRadarView extends FrameLayout {
  16.       
  17. private Paint mPaintNormal; // Brush for drawing normal circles and lines  
  18. private Paint mPaintCircle; // Draw a gradient circle  
  19. private   int w,h; // width and height of the mobile phone screen, width and height of the parent container of the radar view  
  20. private Matrix matrix;
  21. private Handler handler= new Handler();
  22. private   int start;
  23. private Runnable r= new Runnable() {
  24.           
  25. @Override  
  26. public   void run() {
  27. // Execute the loop rotation animation and refresh the UI  
  28. start=start+ 2 ;
  29. matrix= new Matrix();
  30. matrix.postRotate(start, w/ 2 , h/ 2 ); // Set the canvas rotation  
  31. MyRadarView. this .invalidate(); // Refresh UI  
  32. handler.postDelayed(r, 20 );
  33. }
  34. };
  35.       
  36.   
  37. public MyRadarView(Context context, AttributeSet attrs) {
  38. super (context, attrs);
  39. // Initialize the brush  
  40. initPaint();
  41. setBackgroundResource(R.drawable.bg);
  42. // Get the width and height of the mobile phone screen  
  43. this .w=context.getResources().getDisplayMetrics().widthPixels;
  44. this .h=context.getResources().getDisplayMetrics().heightPixels;
  45. handler.post(r);
  46. }
  47.   
  48. /**
  49. * @author Xubin Single QQ:215298766
  50. */  
  51. private   void initPaint() {
  52. mPaintNormal = new Paint(); // Create a brush  
  53. mPaintNormal.setColor(Color.parseColor( "#A1A1A1" ));
  54. mPaintNormal.setStrokeWidth( 3 ); // Set the line  
  55. mPaintNormal.setAntiAlias( true ); // Set anti-aliasing  
  56. mPaintNormal.setStyle(Style.STROKE);
  57.           
  58. // Draw a gradient circle  
  59. mPaintCircle= new Paint();
  60. mPaintCircle.setColor( 0x9D00ff00 ); // Hexadecimal  
  61. mPaintCircle.setAntiAlias( true );
  62. }
  63.       
  64. /**
  65. * Measure the width and height of the control
  66. */  
  67. @Override  
  68. protected   void onMeasure( int widthMeasureSpec, int heightMeasureSpec) {
  69. // Set the width and height of this view  
  70. setMeasuredDimension(w, h);
  71. }
  72.       
  73. /**
  74. * Determine the view of the control
  75. */  
  76. @Override  
  77. protected   void onDraw(Canvas canvas) {
  78. // Screen center, x:w/2, y:h/2  
  79. canvas.drawCircle(w/ 2 , h/ 2 , w/ 6 , mPaintNormal); // Draw a small circle  
  80. canvas.drawCircle(w/ 2 , h/ 2 , 2 *w/ 6 , mPaintNormal); // Draw the circle  
  81. canvas.drawCircle(w/ 2 , h/ 2 , 11 *w/ 20 , mPaintNormal); // Draw the large circle  
  82. canvas.drawCircle(w/ 2 , h/ 2 , 7 *h/ 16 , mPaintNormal); // Draw a large circle  
  83.           
  84. // Draw a gradient circle  
  85. Shader shader= new SweepGradient(w/ 2 , h/ 2 , Color.TRANSPARENT, Color.parseColor( "#AAAAAAAAA" ));
  86. mPaintCircle.setShader(shader);
  87. canvas.concat(matrix);
  88. canvas.drawCircle(w/ 2 , h/ 2 , 7 *h/ 16 , mPaintCircle); //Draw a gradient circle  
  89.           
  90. super .onDraw(canvas);
  91. }
  92. }

Download address: http://download..com/data/2096545

<<:  Cybersecurity firm offers millions for Apple's iOS 9 exploit

>>:  Image sliding gradient

Recommend

How to go on my Android road~

Many students who do Android development want to ...

Tired of Weibo public accounts? Teach you how to use classic RSS subscriptions

We live in an era of unprecedented Internet devel...

APP promotion: How to seize the free channel resources of the app store

CPs! Let’s talk about the app store The group lea...

up to date! Data rankings of 60 information flow advertising platforms!

Today I bring you the latest traffic rankings of ...

The top 10 trends in medical SEM under Baidu’s crackdown!

Written in front Recently, Baidu, the leader in C...

How to plan a successful event promotion?

I believe everyone is familiar with event promoti...

How to modify the DEDECMS backend account?

For website optimization SEO personnel, in additi...

Xiaomi: A department store disguised as a phone manufacturer

This Tuesday, Xiaomi released a number of new pro...

Perhaps this is the "ultimate secret" of user operation

Among all operations , user operation is the most...

How to apply for a 400 telephone number?

Nowadays, there are many 400 telephone service pl...