卫星菜单
详情看demo里面的代码
MainActivity.java
<span style="font-size:18px;">package com.ve.arcmenu; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.imooc.arcmenu.R; import com.ve.arcmenu.view.ArcMenu; import com.ve.arcmenu.view.ArcMenu.OnMenuItemClickListener; import com.ve.arcmenu.view.titlebar; public class MainActivity extends Activity { private ListView mListView; private ArcMenu mArcMenu; private List<String> mDatas; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); titlebar.getTitleBar(this, "卫星菜单"); setContentView(R.layout.activity_main); initData(); initView(); mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDatas)); initEvent(); } private void initEvent() { mListView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mArcMenu.isOpen()) mArcMenu.toggleMenu(600); } }); mArcMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public void onClick(View view, int pos) { Toast.makeText(MainActivity.this, pos+":"+view.getTag(), Toast.LENGTH_SHORT).show(); Intent intent=new Intent(); switch (view.getId()) { case R.id.register: Toast.makeText(MainActivity.this, "register", Toast.LENGTH_SHORT); intent.setClass(MainActivity.this, registerActivity.class); startActivity(intent); finish(); break; case R.id.login: Toast.makeText(MainActivity.this, "login", Toast.LENGTH_SHORT); intent.setClass(MainActivity.this, loginActivity.class); startActivity(intent); finish(); break; default: break; } } }); } private void initData() { mDatas = new ArrayList<String>(); for (int i = 'A'; i < 'Z'; i++) { mDatas.add((char) i + ""); } } private void initView() { mListView = (ListView) findViewById(R.id.id_listview); mArcMenu = (ArcMenu) findViewById(R.id.id_menu); } }</span>
ArcMwnu.java
<span style="font-size:18px;">package com.ve.psychologicalbag.utils;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
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.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import com.ve.psychologicalbag.*;
public class ArcMenu extends ViewGroup implements OnClickListener
{
<span style="white-space:pre"> </span>private static final int POS_LEFT_TOP = 0;
<span style="white-space:pre"> </span>private static final int POS_LEFT_BOTTOM = 1;
<span style="white-space:pre"> </span>private static final int POS_RIGHT_TOP = 2;
<span style="white-space:pre"> </span>private static final int POS_RIGHT_BOTTOM = 3;
<span style="white-space:pre"> </span>private Position mPosition = Position.RIGHT_BOTTOM;
<span style="white-space:pre"> </span>private int mRadius;
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 菜单的状态
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private Status mCurrentStatus = Status.CLOSE;
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 菜单的主按钮
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private View mCButton;
<span style="white-space:pre"> </span>private OnMenuItemClickListener mMenuItemClickListener;
<span style="white-space:pre"> </span>public enum Status
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>OPEN, CLOSE
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 菜单的位置枚举类
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public enum Position
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 点击子菜单项的回调接口
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public interface OnMenuItemClickListener
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>void onClick(View view, int pos);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public void setOnMenuItemClickListener(
<span style="white-space:pre"> </span>OnMenuItemClickListener mMenuItemClickListener)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>this.mMenuItemClickListener = mMenuItemClickListener;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public ArcMenu(Context context)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>this(context, null);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public ArcMenu(Context context, AttributeSet attrs)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>this(context, attrs, 0);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public ArcMenu(Context context, AttributeSet attrs, int defStyle)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>super(context, attrs, defStyle);
<span style="white-space:pre"> </span>//自定义控件使用的类TypedValue
<span style="white-space:pre"> </span>mRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
<span style="white-space:pre"> </span>100, getResources().getDisplayMetrics());
<span style="white-space:pre"> </span>// 获取自定义属性的值
<span style="white-space:pre"> </span>TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
<span style="white-space:pre"> </span>R.styleable.ArcMenu, defStyle, 0);
<span style="white-space:pre"> </span>int pos = a.getInt(R.styleable.ArcMenu_position, POS_RIGHT_BOTTOM);
<span style="white-space:pre"> </span>switch (pos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>case POS_LEFT_TOP:
<span style="white-space:pre"> </span>mPosition = Position.LEFT_TOP;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case POS_LEFT_BOTTOM:
<span style="white-space:pre"> </span>mPosition = Position.LEFT_BOTTOM;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case POS_RIGHT_TOP:
<span style="white-space:pre"> </span>mPosition = Position.RIGHT_TOP;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case POS_RIGHT_BOTTOM:
<span style="white-space:pre"> </span>mPosition = Position.RIGHT_BOTTOM;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>mRadius = (int) a.getDimension(R.styleable.ArcMenu_radius, TypedValue
<span style="white-space:pre"> </span>.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
<span style="white-space:pre"> </span>getResources().getDisplayMetrics()));
<span style="white-space:pre"> </span>Log.e("TAG", "position = " + mPosition + " , radius = " + mRadius);
<span style="white-space:pre"> </span>a.recycle();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 测量子按钮
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int count = getChildCount();
<span style="white-space:pre"> </span>for (int i = 0; i < count; i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>// 测量child
<span style="white-space:pre"> </span>measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>super.onMeasure(widthMeasureSpec, heightMeasureSpec);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>protected void onLayout(boolean changed, int l, int t, int r, int b)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//判断是否发生改变
<span style="white-space:pre"> </span>if (changed)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>layoutCButton();
<span style="white-space:pre"> </span>int count = getChildCount();
<span style="white-space:pre"> </span>for (int i = 0; i < count - 1; i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>View child = getChildAt(i + 1);
<span style="white-space:pre"> </span>//按钮隐藏
<span style="white-space:pre"> </span>child.setVisibility(View.GONE);
<span style="white-space:pre"> </span>//Math.PI / 2==90度 (count - 2) 有几个子菜单项 count包含中间的菜单 * i第几个菜单乘以几倍角
<span style="white-space:pre"> </span>int cl = (int) (mRadius * Math.sin(Math.PI / 2 / (count - 2)
<span style="white-space:pre"> </span>* i));
<span style="white-space:pre"> </span>int ct = (int) (mRadius * Math.cos(Math.PI / 2 / (count - 2)
<span style="white-space:pre"> </span>* i));
<span style="white-space:pre"> </span>int cWidth = child.getMeasuredWidth();
<span style="white-space:pre"> </span>int cHeight = child.getMeasuredHeight();
<span style="white-space:pre"> </span>// 如果菜单位置在左下或者右下
<span style="white-space:pre"> </span>if (mPosition == Position.LEFT_BOTTOM
<span style="white-space:pre"> </span>|| mPosition == Position.RIGHT_BOTTOM)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>ct = getMeasuredHeight() - cHeight - ct;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>// 在右上 右下
<span style="white-space:pre"> </span>if (mPosition == Position.RIGHT_TOP
<span style="white-space:pre"> </span>|| mPosition == Position.RIGHT_BOTTOM)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>cl = getMeasuredWidth() - cWidth - cl;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>//放置子菜单位置
<span style="white-space:pre"> </span>child.layout(cl, ct, cl + cWidth, ct + cHeight);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 定位主菜单按钮
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private void layoutCButton()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>mCButton = getChildAt(0);
<span style="white-space:pre"> </span>mCButton.setOnClickListener(this);
<span style="white-space:pre"> </span>int l = 0;
<span style="white-space:pre"> </span>int t = 0;
<span style="white-space:pre"> </span>//获取宽度
<span style="white-space:pre"> </span>int width = mCButton.getMeasuredWidth();
<span style="white-space:pre"> </span>//获取高度
<span style="white-space:pre"> </span>int height = mCButton.getMeasuredHeight();
<span style="white-space:pre"> </span>//判断位置
<span style="white-space:pre"> </span>switch (mPosition)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>case LEFT_TOP:
<span style="white-space:pre"> </span>l = 0;
<span style="white-space:pre"> </span>t = 0;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case LEFT_BOTTOM:
<span style="white-space:pre"> </span>l = 0;
<span style="white-space:pre"> </span>t = getMeasuredHeight() - height;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case RIGHT_TOP:
<span style="white-space:pre"> </span>l = getMeasuredWidth() - width;
<span style="white-space:pre"> </span>t = 0;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case RIGHT_BOTTOM:
<span style="white-space:pre"> </span>l = getMeasuredWidth() - width;
<span style="white-space:pre"> </span>t = getMeasuredHeight() - height;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>mCButton.layout(l, t, l + width, t + width);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onClick(View v)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>//确认mCButton的值
<span style="white-space:pre"> </span>// mCButton = findViewById(R.id.id_button);
<span style="white-space:pre"> </span>// if(mCButton == null)
<span style="white-space:pre"> </span>// {
<span style="white-space:pre"> </span>// mCButton = getChildAt(0);
<span style="white-space:pre"> </span>// }
<span style="white-space:pre"> </span>//旋转动画 view 开始角度 结束角度 时间300ms
<span style="white-space:pre"> </span>rotateCButton(v, 0f, 360f, 300);
<span style="white-space:pre"> </span>//
<span style="white-space:pre"> </span>toggleMenu(300);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 切换菜单
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public void toggleMenu(int duration)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>// 为menuitem添加动画
<span style="white-space:pre"> </span>int count = getChildCount();
<span style="white-space:pre"> </span>for (int i = 0; i < count - 1; i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>final View childView = getChildAt(i + 1);
<span style="white-space:pre"> </span>//先显示才会有动画
<span style="white-space:pre"> </span>childView.setVisibility(View.VISIBLE);
<span style="white-space:pre"> </span>// end 0 , 0 因为按钮本来就在那个位置 不需要考虑最后的位置
<span style="white-space:pre"> </span>// start
<span style="white-space:pre"> </span>int cl = (int) (mRadius * Math.sin(Math.PI / 2 / (count - 2) * i));
<span style="white-space:pre"> </span>int ct = (int) (mRadius * Math.cos(Math.PI / 2 / (count - 2) * i));
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>int xflag = 1;
<span style="white-space:pre"> </span>int yflag = 1;
<span style="white-space:pre"> </span>//判断正负 左上左下 x要减
<span style="white-space:pre"> </span>if (mPosition == Position.LEFT_TOP
<span style="white-space:pre"> </span>|| mPosition == Position.LEFT_BOTTOM)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>xflag = -1;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>//判断正负 左上右下 y要减
<span style="white-space:pre"> </span>if (mPosition == Position.LEFT_TOP
<span style="white-space:pre"> </span>|| mPosition == Position.RIGHT_TOP)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>yflag = -1;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>AnimationSet animset = new AnimationSet(true);
<span style="white-space:pre"> </span>Animation tranAnim = null;
<span style="white-space:pre"> </span>// to open
<span style="white-space:pre"> </span>if (mCurrentStatus == Status.CLOSE)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>tranAnim = new TranslateAnimation(xflag * cl, 0, yflag * ct, 0);
<span style="white-space:pre"> </span>childView.setClickable(true);
<span style="white-space:pre"> </span>childView.setFocusable(true);
<span style="white-space:pre"> </span>} else
<span style="white-space:pre"> </span>// to close
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>tranAnim = new TranslateAnimation(0, xflag * cl, 0, yflag * ct);
<span style="white-space:pre"> </span>childView.setClickable(false);
<span style="white-space:pre"> </span>childView.setFocusable(false);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>//设置xuanz
<span style="white-space:pre"> </span>tranAnim.setFillAfter(true);
<span style="white-space:pre"> </span>//设置路径
<span style="white-space:pre"> </span>tranAnim.setDuration(duration);
<span style="white-space:pre"> </span>//设置子菜单出去的速度
<span style="white-space:pre"> </span>tranAnim.setStartOffset((i * 100) / count);
<span style="white-space:pre"> </span>tranAnim.setAnimationListener(new AnimationListener()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onAnimationStart(Animation animation)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onAnimationRepeat(Animation animation)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onAnimationEnd(Animation animation)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>if (mCurrentStatus == Status.CLOSE)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>childView.setVisibility(View.GONE);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>});
<span style="white-space:pre"> </span>// 小菜单旋转动画 转两圈
<span style="white-space:pre"> </span>RotateAnimation rotateAnim = new RotateAnimation(0, 720,
<span style="white-space:pre"> </span>Animation.RELATIVE_TO_SELF, 0.5f,
<span style="white-space:pre"> </span>Animation.RELATIVE_TO_SELF, 0.5f);
<span style="white-space:pre"> </span>rotateAnim.setDuration(duration);
<span style="white-space:pre"> </span>rotateAnim.setFillAfter(true);
<span style="white-space:pre"> </span>animset.addAnimation(rotateAnim);
<span style="white-space:pre"> </span>animset.addAnimation(tranAnim);
<span style="white-space:pre"> </span>childView.startAnimation(animset);
<span style="white-space:pre"> </span>final int pos = i + 1;
<span style="white-space:pre"> </span>//设置子菜单点击事件
<span style="white-space:pre"> </span>childView.setOnClickListener(new OnClickListener()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onClick(View v)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>if (mMenuItemClickListener != null)
<span style="white-space:pre"> </span>mMenuItemClickListener.onClick(childView, pos);
<span style="white-space:pre"> </span>menuItemAnim(pos - 1);
<span style="white-space:pre"> </span>changeStatus();
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>});
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>//菜单状态改变
<span style="white-space:pre"> </span>changeStatus();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 添加子菜单的点击动画
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * @param i
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private void menuItemAnim(int pos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>for (int i = 0; i < getChildCount() - 1; i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>View childView = getChildAt(i + 1);
<span style="white-space:pre"> </span>if (i == pos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>childView.startAnimation(scaleBigAnim(300));
<span style="white-space:pre"> </span>} else
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>childView.startAnimation(scaleSmallAnim(300));
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>childView.setClickable(false);
<span style="white-space:pre"> </span>childView.setFocusable(false);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>private Animation scaleSmallAnim(int duration)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>AnimationSet animationSet = new AnimationSet(true);
<span style="white-space:pre"> </span>ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f,
<span style="white-space:pre"> </span>Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
<span style="white-space:pre"> </span>0.5f);
<span style="white-space:pre"> </span>AlphaAnimation alphaAnim = new AlphaAnimation(1f, 0.0f);
<span style="white-space:pre"> </span>animationSet.addAnimation(scaleAnim);
<span style="white-space:pre"> </span>animationSet.addAnimation(alphaAnim);
<span style="white-space:pre"> </span>animationSet.setDuration(duration);
<span style="white-space:pre"> </span>animationSet.setFillAfter(true);
<span style="white-space:pre"> </span>return animationSet;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 为当前点击的item设置变大和透明降低
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * @param duration
<span style="white-space:pre"> </span> * @return
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private Animation scaleBigAnim(int duration)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>AnimationSet animationSet = new AnimationSet(true);
<span style="white-space:pre"> </span>ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,
<span style="white-space:pre"> </span>Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
<span style="white-space:pre"> </span>0.5f);
<span style="white-space:pre"> </span>AlphaAnimation alphaAnim = new AlphaAnimation(1f, 0.0f);
<span style="white-space:pre"> </span>animationSet.addAnimation(scaleAnim);
<span style="white-space:pre"> </span>animationSet.addAnimation(alphaAnim);
<span style="white-space:pre"> </span>animationSet.setDuration(duration);
<span style="white-space:pre"> </span>animationSet.setFillAfter(true);
<span style="white-space:pre"> </span>return animationSet;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 切换菜单状态
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private void changeStatus()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>mCurrentStatus = (mCurrentStatus == Status.CLOSE ? Status.OPEN
<span style="white-space:pre"> </span>: Status.CLOSE);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public boolean isOpen()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>return mCurrentStatus == Status.OPEN;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 设置主菜单按钮 旋转 动画
<span style="white-space:pre"> </span> * @param v
<span style="white-space:pre"> </span> * @param start
<span style="white-space:pre"> </span> * @param end
<span style="white-space:pre"> </span> * @param duration
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>private void rotateCButton(View v, float start, float end, int duration)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>RotateAnimation anim = new RotateAnimation(start, end,
<span style="white-space:pre"> </span>Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
<span style="white-space:pre"> </span>0.5f);
<span style="white-space:pre"> </span>anim.setDuration(duration);
<span style="white-space:pre"> </span>anim.setFillAfter(true);
<span style="white-space:pre"> </span>v.startAnimation(anim);
<span style="white-space:pre"> </span>}
}</span>
titlebar.java
<span style="font-size:18px;">package com.ve.arcmenu.view;
import com.imooc.arcmenu.R;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
public class titlebar {
private static Activity mActivity;
/**
* @see [自定义标题栏]
* @param activity
* @param title
*/
public static void getTitleBar(Activity activity,String title) {
mActivity = activity;
activity.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
activity.setContentView(R.layout.titlebar);
activity.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.titlebar);
TextView textView = (TextView) activity.findViewById(R.id.textView1);
textView.setText(title);
Button titleBackBtn = (Button) activity.findViewById(R.id.moreBtn);
titleBackBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
KeyEvent newEvent = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_BACK);
mActivity.onKeyDown(KeyEvent.KEYCODE_BACK, newEvent);
}
});
}
}</span>
attr.xml
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="position">
<enum name="left_top" value="0" />
<enum name="left_bottom" value="1" />
<enum name="right_top" value="2" />
<enum name="right_bottom" value="3" />
</attr>
<attr name="radius" format="dimension" />
<declare-styleable name="ArcMenu">
<attr name="position" />
<attr name="radius" />
</declare-styleable>
</resources></span>
style.xml
<span style="font-size:18px;"><resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="TitleBarBackground">
<item name="android:background">@color/blue</item>
</style>
<style name="MyCustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@style/TitleBarBackground</item>
<item name="android:windowTitleSize">50dp</item>
</style>
</resources></span>
Demo下载链接:点击打开链接