Android 实现卫星导航
来源:互联网 发布:软件光盘品牌 编辑:程序博客网 时间:2024/04/30 12:57
类似这种点击展开的效果package com.example.arcmenu;import android.content.Context;import android.content.res.TypedArray;import android.util.AttributeSet;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.TranslateAnimation;public class ArcMenu extends ViewGroup implements OnClickListener { public enum Position { LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM } private Position mPosition = Position.RIGHT_BOTTOM; private int mRadius; private Status mCurrentStatus = Status.CLOSE; private String[] tags = { "camera", "music", "sleep", "place", "thought" }; private View ivButton; public enum Status { OPEN, CLOSE; } private onMenuItemListener mMenuItemListener; public void setmMenuItemListener(onMenuItemListener mMenuItemListener) { this.mMenuItemListener = mMenuItemListener; } public interface onMenuItemListener { void onClick(View view, int pos); } int mAttr[] = { R.attr.position, R.attr.radius }; public ArcMenu(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, mAttr); mRadius = ta.getDimensionPixelSize(1, 0); int pos = ta.getInt(0, 3); switch (pos) { case 0: mPosition = Position.LEFT_TOP; break; case 1: mPosition = Position.LEFT_BOTTOM; break; case 2: mPosition = Position.RIGHT_TOP; break; case 3: mPosition = Position.RIGHT_BOTTOM; break; } ta.recycle(); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (changed) { layoutMainButton(); layoutItem(); } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); for (int i = 0; i < getChildCount(); i++) { measureChild(getChildAt(0), widthMeasureSpec, heightMeasureSpec); } } private void layoutMainButton() { ivButton = getChildAt(0); ivButton.setOnClickListener(this); int left = 0, top = 0, width = ivButton.getMeasuredWidth(), height = ivButton .getMeasuredHeight(), right, bottom; switch (mPosition) { case LEFT_TOP: left = 0; top = 0; break; case LEFT_BOTTOM: left = 0; top = getMeasuredHeight() - height; break; case RIGHT_TOP: left = getMeasuredWidth() - width; top = 0; break; case RIGHT_BOTTOM: left = getMeasuredWidth() - width; top = getMeasuredHeight() - height; break; default: break; } right = left + width; bottom = top + height; ivButton.layout(left, top, right, bottom); } private void layoutItem() { float angle = 90 * 1f / (tags.length - 1); float itemAngle = 0; double startX = 0, startY = 0, endX = 0, endY = 0; ivButton.measure(0, 0); for (int i = 0; i < tags.length; i++) { View child = findViewWithTag(tags[i]); child.setVisibility(View.GONE); child.measure(0, 0); switch (mPosition) { case LEFT_TOP: startX = 0; startY = ivButton.getMeasuredHeight() / 2; endX = startX + mRadius * Math.cos(Math.toRadians(itemAngle)); endY = startY + mRadius * Math.sin(Math.toRadians(itemAngle)); break; case LEFT_BOTTOM: startX = 0; startY = getMeasuredHeight(); endX = startX + mRadius * Math.cos(Math.toRadians(itemAngle)); endY = startY - mRadius * Math.sin(Math.toRadians(itemAngle)) - child.getMeasuredHeight(); break; case RIGHT_TOP: startX = getMeasuredWidth(); startY = 0; endX = startX - mRadius * Math.cos(Math.toRadians(itemAngle)) - child.getMeasuredWidth(); endY = startY + mRadius * Math.sin(Math.toRadians(itemAngle)); break; case RIGHT_BOTTOM: startX = getMeasuredWidth(); startY = getMeasuredHeight(); endX = startX - mRadius * Math.cos(Math.toRadians(itemAngle)) - child.getMeasuredWidth(); endY = startY - mRadius * Math.sin(Math.toRadians(itemAngle)) - child.getMeasuredHeight(); break; default: break; } child.layout((int) endX, (int) endY, (int) (endX + child.getMeasuredWidth()), (int) (endY + child.getMeasuredHeight())); itemAngle += angle; } } private void toggleMenu(int duration) { float angle = 90 * 1f / (tags.length - 1); float itemAngle = 0; double startX = 0, startY = 0, endX = 0, endY = 0; for (int i = 0; i < tags.length; i++) { final View child = findViewWithTag(tags[i]); child.measure(0, 0); child.setVisibility(View.VISIBLE); switch (mPosition) { case LEFT_TOP: startX = 0; startY = 0; endX = startX + mRadius * Math.cos(Math.toRadians(itemAngle)); endY = startY + mRadius * Math.sin(Math.toRadians(itemAngle)); break; case LEFT_BOTTOM: startX = 0; startY = getMeasuredHeight(); endX = startX + mRadius * Math.cos(Math.toRadians(itemAngle)); endY = startY - mRadius * Math.sin(Math.toRadians(itemAngle)) - child.getMeasuredHeight(); break; case RIGHT_TOP: startX = getMeasuredWidth(); startY = 0; endX = startX - mRadius * Math.cos(Math.toRadians(itemAngle)) - child.getMeasuredWidth(); endY = startY + mRadius * Math.sin(Math.toRadians(itemAngle)); break; case RIGHT_BOTTOM: startX = getMeasuredWidth(); startY = getMeasuredHeight(); endX = startX - mRadius * Math.cos(Math.toRadians(itemAngle)) - child.getMeasuredWidth(); endY = startY - mRadius * Math.sin(Math.toRadians(itemAngle)) - child.getMeasuredHeight(); break; default: break; } itemAngle += angle; AnimationSet animSet = new AnimationSet(true); animSet.setDuration(duration); TranslateAnimation animation = null; RotateAnimation rotaAnimation = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF,0.5f, RotateAnimation.RELATIVE_TO_SELF,0.5f); if (mCurrentStatus == Status.CLOSE) { animation = new TranslateAnimation( (float) (-endX + startX), 0, (float) (-endY + startY) - ivButton.getMeasuredHeight(), 0); } else { animation = new TranslateAnimation(0, (float) (-endX + startX), 0, (float) (-endY + startY) - ivButton.getMeasuredHeight()); } animSet.addAnimation(rotaAnimation); animSet.addAnimation(animation); animSet.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (mCurrentStatus == Status.CLOSE) { child.clearAnimation(); child.setVisibility(View.GONE); } } }); animSet.setFillAfter(true); child.startAnimation(animSet); } if (mCurrentStatus == Status.CLOSE) { mCurrentStatus = Status.OPEN; } else { mCurrentStatus = Status.CLOSE; } } @Override public void onClick(View v) { if (ivButton == v) { toggleMenu(2000); } }}http://download.csdn.net/detail/luo446718254/9636644
0 0
- Android 实现卫星导航
- android自定义ViewGroup卫星导航菜单
- Android卫星菜单的实现
- GPS卫星导航电文
- Android卫星弹射菜单ArcMenu实现
- 基于Android的卫星菜单效果实现
- Android笔记之卫星菜单的实现
- Android 实现自定义的卫星式菜单
- android卫星菜单的简单实现
- Android实现仿卫星式动画菜单
- 超市里需要卫星导航?
- GLONASS全球导航卫星系统
- 多模卫星导航接收机
- 多模卫星导航接收机
- 卫星导航开源代码库
- android实现导航栏
- Android 逆向分析之 : GPS卫星定位监控导航寻找人
- Android自定义VIew之实现卫星菜单效果
- 【项目4-圆柱表面积】 第四周
- OpenGl入门
- ALSA lib调用实例
- springMVC初识,前台页面传入后台的4种方法
- tcp四次挥手
- Android 实现卫星导航
- [Leetcode] Summary Ranges
- 关于Xcode报错, 但编译,运行正常情况
- java实现一个栈
- Android的对话框显示与隐藏
- C#中使用托管C++类,委托调用,以供托管C++类的成员函数回调的实现方式
- 程序员技巧---调试
- redis
- spring mvc 使用kaptcha生成验证码