您好,欢迎光临本网站![请登录][注册会员]  
文件名称: Android酷炫转动菜单
  所属分类: Android
  开发工具:
  文件大小: 3mb
  下载次数: 0
  上传时间: 2015-08-19
  提 供 者: qq_25******
 详细说明: package com.zhy.view; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.zhy.ccbCricleMenu.R; public class CircleMenuLayout extends ViewGroup { /** * layout的半径 */ private int mRadius; private float mMaxChildDimesionRadio = 1 / 4f; private float mCenterItemDimesionRadio = 1 / 3f; private LayoutInflater mInflater; private double mStartAngle = 0; private String[] mItemTexts = new String[] { "安全中心 ", "特色服务", "投资理财", "转账汇款", "我的账户", "信用卡" }; private int[] mItemImgs = new int[] { R.drawable.home_mbank_1_normal, R.drawable.home_mbank_2_normal, R.drawable.home_mbank_3_normal, R.drawable.home_mbank_4_normal, R.drawable.home_mbank_5_normal, R.drawable.home_mbank_6_normal }; private int mTouchSlop; /** * 加速度检测 */ private float mDownAngle; private float mTmpAngle; private long mDownTime; private boolean isFling; public CircleMenuLayout(Context context, AttributeSet attrs) { super(context, attrs); mInflater = LayoutInflater.from(context); for (int i = 0; i < mItemImgs.length; i++) { final int j = i; View view = mInflater.inflate(R.layout.turnpalte_inner_view, this, false); ImageView iv = (ImageView) view .findViewById(R.id.id_circle_menu_item_image); TextView tv = (TextView) view .findViewById(R.id.id_circle_menu_item_text); iv.setImageResource(mItemImgs[i]); tv.setText(mItemTexts[i]); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), mItemTexts[j], Toast.LENGTH_SHORT).show(); } }); addView(view); } mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(getSuggestedMinimumWidth(), getSuggestedMinimumHeight()); // 获得半径 mRadius = Math.max(getWidth(), getHeight()); final int count = getChildCount(); // Log.e("TAG", count + ""); int childSize = (int) (mRadius * mMaxChildDimesionRadio); int childMode = MeasureSpec.EXACTLY; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } int makeMeasureSpec = -1; if (child.getId() == R.id.id_circle_menu_item_center) { makeMeasureSpec = MeasureSpec.makeMeasureSpec( (int) (mRadius * mCenterItemDimesionRadio), childMode); } else { makeMeasureSpec = MeasureSpec.makeMeasureSpec(childSize, childMode); } child.measure(makeMeasureSpec, makeMeasureSpec); } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int layoutWidth = r - l; int layoutHeight = b - t; int layoutRadius = Math.max(layoutWidth, layoutHeight); // Laying out the child views final int childCount = getChildCount(); int left, top; int radius = (int) (layoutRadius * mMaxChildDimesionRadio); float angleDelay = 360 / (getChildCount() - 1); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getId() == R.id.id_circle_menu_item_center) continue; if (child.getVisibility() == GONE) { continue; } mStartAngle %= 360; float tmp = layoutRadius * 1f / 3 - 1 / 22f * layoutRadius; left = layoutRadius / 2 + (int) Math.round(tmp * Math.cos(Math.toRadians(mStartAngle)) - 1 / 2f * radius); top = layoutRadius / 2 + (int) Math.round(tmp * Math.sin(Math.toRadians(mStartAngle)) - 1 / 2f * radius); // Log.e("TAG", "left = " + left + " , top = " + top); child.layout(left, top, left + radius, top + radius); mStartAngle += angleDelay; } View cView = findViewById(R.id.id_circle_menu_item_center); cView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "you can do something just like ccb ", Toast.LENGTH_SHORT).show(); } }); // Log.e("TAG", // cView.getMeasuredWidth() + " , " + cView.getMeasuredWidth()); int cl = layoutRadius / 2 - cView.getMeasuredWidth() / 2; int cr = cl + cView.getMeasuredWidth(); cView.layout(cl, cl, cr, cr); } private float mLastX; private float mLastY; private FlingRunnable mFlingRunnable; // @Override // public boolean onTouchEvent(MotionEvent event) // { // } @Override public boolean dispatchTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mLastX = x; mLastY = y; mDownAngle = getAngle(x, y); mDownTime = System.currentTimeMillis(); mTmpAngle = 0; if (isFling) { removeCallbacks(mFlingRunnable); isFling = false; return true ; } break; case MotionEvent.ACTION_MOVE: float start = getAngle(mLastX, mLastY); float end = getAngle(x, y); // Log.e("TAG", "start = " + start + " , end =" + end); if (getQuadrant(x, y) == 1 || getQuadrant(x, y) == 4) { mStartAngle += end - start; mTmpAngle += end - start; } else { mStartAngle += start - end; mTmpAngle += start - end; } // rotateButtons((float) (mStartAngle - currentAngle)); requestLayout(); mLastX = x; mLastY = y; break; case MotionEvent.ACTION_UP: float anglePrMillionSecond = mTmpAngle * 1000 / (System.currentTimeMillis() - mDownTime); Log.e("TAG", anglePrMillionSecond + " , mTmpAngel = " + mTmpAngle); if (Math.abs(anglePrMillionSecond) > 230 && !isFling) { post(mFlingRunnable = new FlingRunnable(anglePrMillionSecond)); } if(Math.abs(anglePrMillionSecond) >230 || isFling) { return true ; } break; } return super.dispatchTouchEvent(event); } private float getAngle(float xTouch, float yTouch) { double x = xTouch - (mRadius / 2d); double y = yTouch - (mRadius / 2d); return (float) (Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI); } private int getQuadrant(float x, float y) { int tmpX = (int) (x - mRadius / 2); int tmpY = (int) (y - mRadius / 2); if (tmpX >= 0) { return tmpY >= 0 ? 4 : 1; } else { return tmpY >= 0 ? 3 : 2; } } private class FlingRunnable implements Runnable { private float velocity; public FlingRunnable(float velocity) { this.velocity = velocity; } public void run() { if ((int) Math.abs(velocity) < 20) { isFling = false; return; } isFling = true; // rotateButtons(velocity / 75); mStartAngle += (velocity / 30); velocity /= 1.0666F; postDelayed(this, 30); requestLayout(); Log.e("TAG", velocity + ""); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 菜单旋转动画
 输入关键字,在本站1000多万海量源码库中尽情搜索: