Android programming simple implementation of radar scanning effect-java tutorial

Source: Internet
Author: User
This article mainly introduces the simple implementation of radar scanning by Android programming. it involves Android graphics rendering and display techniques and has some reference value, for more information about Android programming, see the following example. We will share this with you for your reference. The details are as follows:

I saw an article on radar scanning in eoe, and then I read it. it's very simple, but I think there are still many things to be optimized. I will post it below.

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(Context context) {  super(context);  init(); } public RadarView(Context 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, viewSize); } 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 Android program design.

For more articles about how Android programming is simple to implement radar scanning, please follow the PHP Chinese network!

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.