我是靠谱客的博主 彪壮小鸭子,最近开发中收集的这篇文章主要介绍Android百度地图雷达效果,实现百度地图的身边雷达的功能效果,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

package cn.com.sric.android_radio;

import android.content.Context;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Matrix;

import android.graphics.Paint;

import android.graphics.Shader;

import android.graphics.SweepGradient;

import android.util.AttributeSet;

import android.view.KeyEvent;

import android.view.View;

public class SampleView extends View {

private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

private float mRotate;

private Matrix mMatrix = new Matrix();

private Shader mShader;

private boolean mDoTiming;

float x = 160;// 旋转的原点x

float y = 160;// 旋转的原点y

public SampleView(Context context) {

super(context);

}

public SampleView(Context context, AttributeSet paramAttributeSet) {

super(context, paramAttributeSet);

setFocusable(true);

setFocusableInTouchMode(true);

mShader = new SweepGradient(x, y, new int[] {

R.drawable.component_radar_pointer, Color.TRANSPARENT }, null);

mPaint.setShader(mShader);

}

@Override

protected void onDraw(Canvas canvas) {

Paint paint = mPaint;

Paint ppPaint = new Paint();

ppPaint.setColor(Color.WHITE);

canvas.drawColor(Color.TRANSPARENT);

// canvas.setBitmap(getResources().getDrawable(R.drawable.component_radar_board));

mMatrix.setRotate(mRotate, x, y);

mShader.setLocalMatrix(mMatrix);

mRotate += 2.5;// 设置旋转速度

if (mRotate >= 360) {

mRotate = 0;

}

invalidate();

if (mDoTiming) {

long now = System.currentTimeMillis();

for (int i = 0; i < 30; i++) {

canvas.drawCircle(x, y, 80, paint);

}

now = System.currentTimeMillis() - now;

android.util.Log.d("skia", "sweep ms = " + (now / 20.));

} else {

// canvas添加的图层也有一个堆载的形式,先绘制的图像在底层

canvas.drawCircle(x, y, 118, paint);

canvas.drawCircle(x, y, 3, ppPaint);

Resources r = getResources();

Bitmap bp = BitmapFactory.decodeResource(r,

R.drawable.component_radar_light_point);

canvas.drawBitmap(bp, 100, 120, paint);

canvas.drawBitmap(bp, 120, 130, paint);

canvas.drawBitmap(bp, 170, 110, paint);

canvas.drawBitmap(bp, 180, 100, paint);

canvas.drawBitmap(bp, 230, 199, paint);

canvas.drawBitmap(bp, 200, 249, paint);

canvas.drawBitmap(bp, 158, 210, paint);

}

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

switch (keyCode) {

case KeyEvent.KEYCODE_D:

mPaint.setDither(!mPaint.isDither());

invalidate();

return true;

case KeyEvent.KEYCODE_T:

mDoTiming = !mDoTiming;

invalidate();

return true;

}

return super.onKeyDown(keyCode, event);

}

}

四、实现效果图

最后

以上就是彪壮小鸭子为你收集整理的Android百度地图雷达效果,实现百度地图的身边雷达的功能效果的全部内容,希望文章能够帮你解决Android百度地图雷达效果,实现百度地图的身边雷达的功能效果所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部