Android programming simple to achieve radar scanning effect _android

Source: Internet
Author: User
Tags int size radar

The example of this article describes the Android programming simple to achieve radar scanning effect. Share to everyone for your reference, specific as follows:

In EoE saw an article about radar scanning, and then looked at, very simple, but think there are many can optimize the place, the following posted out

Package com.example.wave;
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.util.AttributeSet;
Import Android.widget.FrameLayout;
 public class Radarview extends Framelayout {private int viewsize = 500;
 Private Paint Mpaintline;
 Private Paint Mpaintsector;
 Private Boolean isstart = false;
 Private Scanthread Mthread;
 private int start = 0;
 Private final int paintwidth = 10;
  Public Radarview {Super (context);
 Init ();
  Public Radarview (context, AttributeSet attrs) {Super (context, attrs);
 Init ();
  private void Init () {initpaint ();
  Mthread = new Scanthread ();
 SetBackgroundColor (color.transparent);
  private void Initpaint () {mpaintline = new Paint ();
  Mpaintline.setstrokewidth (Paintwidth); Mpaintline.Setantialias (TRUE);
  Mpaintline.setstyle (Style.stroke);
  Mpaintline.setcolor (0xffff0000);
  Mpaintsector = new Paint ();
  Mpaintsector.setcolor (0X9D00FF00);
 Mpaintsector.setantialias (TRUE);
  public void setviewsize (int size) {this.viewsize = size;
  Mshader = new Sweepgradient (viewsize >> 1, viewsize >> 1, color.transparent, Color.green);
 Setmeasureddimension (Viewsize, viewsize); @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {setmeasureddimension (viewsize, Vie
 Wsize);
  public void Start () {Mthread.start ();
 Isstart = true;
   public void Stop () {if (Isstart) {thread.interrupted ();
  Isstart = false; } private Shader Mshader = new Sweepgradient (viewsize >> 1, viewsize >> 1, color.transparent, Color.green)
 ;
 Private Matrix matrix = new Matrix ();
  @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
  int halfradasize = viewsize >> 1; Canvas.drawcircle (HalfradasiZe, halfradasize, halfradasize >> 1, mpaintline);
  Canvas.drawcircle (Halfradasize, Halfradasize, Halfradasize-(paintwidth >> 1), mpaintline);
  Canvas.drawline (halfradasize, 0, Halfradasize, viewsize, mpaintline);
  Canvas.drawline (0, Halfradasize, viewsize, Halfradasize, mpaintline);
  Mpaintsector.setshader (Mshader);
  Canvas.concat (matrix);
 Canvas.drawcircle (Halfradasize, Halfradasize, Halfradasize-paintwidth, mpaintsector);
  } protected class Scanthread extends Thread {int halfradasize = viewsize >> 1;
    @Override public void Run () {while (Isstart) {start = start + 2;
    Matrix.reset ();
    Matrix.postrotate (Start, halfradasize, halfradasize);
    Postinvalidate ();
    try {thread.sleep (10);
    catch (Interruptedexception e) {e.printstacktrace ();

 }
   }
  }
 }
}

I hope this article will help you with your Android programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.