仿雷达搜索
来源:互联网 发布:mac总是提示安装迅雷 编辑:程序博客网 时间:2024/04/29 01:43
网上下载了几张图片,做了个demo
资源下载:http://download.csdn.net/detail/hello_12413/8601533
别的不说了,直接上图上代码
代码如下:
package com.example.actionbaraddui;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Matrix;import android.graphics.Paint;import android.graphics.Point;import android.graphics.RectF;import android.os.Handler;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;/** * @project javaapk.com-ActionBarAddUI * @ClassName ScanView.java * @Description 搜索页面,模仿雷达 背景不动,指针转动 * @author xugang * @date 2015-4-9 下午5:04:08 */public class ScanView extends View implements Runnable {/** 转盘 */private Bitmap plate;/** 指针 */private Bitmap pointer;private Bitmap btn;private float Angel = 0.0f;private Matrix matx = new Matrix();private boolean isStopRoter = false;private Point mPoint;public ScanView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);new Thread(this).start();}public ScanView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public ScanView(Context context) {this(context, null);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);init();canvas.restore();Paint paintPlate = new Paint();canvas.drawBitmap(plate, (canvas.getWidth() - plate.getWidth()) / 2, (canvas.getHeight() - plate.getHeight()) / 2, paintPlate);matx.reset();matx.setTranslate(canvas.getWidth() / 2 - pointer.getWidth(), canvas.getHeight() / 2);matx.postRotate(Angel, canvas.getWidth() / 2, canvas.getHeight() / 2);Paint paintPointer = new Paint();canvas.drawBitmap(pointer, matx, paintPointer);Paint paintBtn = new Paint();canvas.drawBitmap(btn, (canvas.getWidth() - btn.getWidth()) / 2, (canvas.getHeight() - btn.getHeight()) / 2, paintBtn);mPoint = new Point(canvas.getWidth() / 2, canvas.getHeight() / 2);}private void init() {if (plate == null)plate = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.gplus_search_bg));if (btn == null)btn = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.locus_round_click));if (pointer == null)pointer = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.gplus_search_args));}Handler handler = new Handler() {public void handleMessage(android.os.Message msg) {invalidate();};};@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:handleActionDownEvenet(event);return true;case MotionEvent.ACTION_MOVE:return true;case MotionEvent.ACTION_UP:return true;}return super.onTouchEvent(event);}//判断是否点击了中间点private void handleActionDownEvenet(MotionEvent event) {int x = (int) event.getX();int y = (int) event.getY();RectF rectF = new RectF(getWidth() / 2 - btn.getWidth() / 2, getHeight() / 2 - btn.getHeight() / 2, getWidth() / 2 + btn.getWidth() / 2, getHeight() / 2 + btn.getHeight() / 2);if (rectF.contains(event.getX(), event.getY())) {isStopRoter = !isStopRoter;}}@Overridepublic void run() {while (true) {try {Thread.sleep(40);} catch (InterruptedException e) {e.printStackTrace();}if (isStopRoter) {Angel += 5;handler.sendEmptyMessage(1);}}}}
遗留问题:1、大小不能随意变化,这个还需要研究研究。
2、用的是矩阵变化,这里有个前乘和后乘的问题
0 0
- 仿雷达搜索
- Android 仿微信雷达搜索好友
- 仿微信雷达搜索好友特效
- 用 VML 实现仿雷达扫描效果
- Android 自定义View --仿雷达扫瞄
- 雷达
- Android仿新浪微博雷达扫描效果
- Android自定义View—仿雷达扫描效果
- iOS核心动画实现仿支付宝咻咻、雷达效果
- 仿Google搜索框
- 仿google搜索提示
- 仿百度搜索框
- 仿百度搜索代码
- Vue 仿百度搜索
- 仿淘宝搜索框
- 仿IOS搜索框
- MVP+okhttp仿搜索
- 仿百度搜索
- 关于 "未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0, 错误的解决方案
- Android应用程序窗口设计框架介绍
- explain 命令参数详解
- Python中的input()和raw_input()
- WCF中的Stream操作
- 仿雷达搜索
- 黑马程序员:IO流之字节流
- 在myeclipse中根据数据库中的表格自动生成类
- this message is already use 解决
- mui datagride 头部及表格内容居中
- C++:智能指针
- 浅析用Base64编码的图片优化网页加载速度
- AutoCAD I/O - 第一篇(简介)
- Acdream 1132 Chess(状压dp)