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

60 Lectures on Chinese Literature Masterpieces Baidu Cloud Download

60 Lectures on Chinese Literature Masterpieces Re...

How many megabytes of bandwidth does a short video server require for rental?

Short video platforms are the most popular traffi...

Li Bingjun's resume: The key points of on-site SEO promotion

On-site SEO promotion focuses on on-site SEO opti...

Why does the world map only have 4 colors?

On a world map, how many colors are needed to col...

In the new era, what kind of learning ability do we need?

Bacon once said: Knowledge is power. However, onl...

Trash! Why is the usage rate so low every time a coupon is issued?

Coupons are widely used, from offline stores to o...

iQiyi advertising account opening, iQiyi promotion billing

The average online time of iQiyi users is long an...

Is it contradictory to protect a certain species with protecting biodiversity?

A few days ago (May 22) was the International Day...

Do you understand these permissions in iOS development?

Preface App development should avoid the problem ...