android 径向菜单,Android径向/饼图菜单

下面有View类ondraw()方法来绘制径向菜单..

@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, mShadowColor); //Draw the menu if the menu is to be displayed. if(isMenuVisible) { canvas.drawArc(mMenuRect, mStartAngle, 180, true, mRadialMenuPaint); //See if there is any item in the collection if(mMenuItems.size() > 0) { float mStart = mStartAngle; //Get the sweep angles based on the number of menu items float mSweep = 180/mMenuItems.size(); for(SemiCircularRadialMenuItem item : mMenuItems.values()) { mRadialMenuPaint.setColor(item.getBackgroundColor()); item.setMenuPath(mMenuCenterButtonRect, mMenuRect, mStart, mSweep, mRadius, mViewAnchorPoints); canvas.drawPath(item.getMenuPath(), mRadialMenuPaint); if(isShowMenuText) { mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, Color.TRANSPARENT); mRadialMenuPaint.setColor(item.getTextColor()); canvas.drawTextOnPath(item.getText(), item.getMenuPath(), 5, textSize, mRadialMenuPaint); mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, mShadowColor); } item.getIcon().draw(canvas); mStart += mSweep; } mRadialMenuPaint.setStyle(Style.FILL); } } //Draw the center menu toggle piece mRadialMenuPaint.setColor(centerRadialColor); canvas.drawArc(mMenuCenterButtonRect, mStartAngle, 180, true, mRadialMenuPaint); mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, Color.TRANSPARENT); //Draw the center text drawCenterText(canvas, mRadialMenuPaint); }

并且还管理触摸事件中的X,Y坐标以触摸项目菜单

@Override public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if(mMenuCenterButtonRect.contains(x, y-15)) { centerRadialColor = RadialMenuColors.HOLO_LIGHT_BLUE; isMenuTogglePressed = true; invalidate(); } else if(isMenuVisible) { if(mMenuItems.size() > 0) { for(SemiCircularRadialMenuItem item : mMenuItems.values()) { if(mMenuRect.contains((int) x+20, (int) y)) if(item.getBounds().contains((int) x+20, (int) y)) { System.out.println("get x...> " + x); System.out.println("get y...> " + y); isMenuItemPressed = true; mPressedMenuItemID = item.getMenuID(); break; } } mMenuItems.get(mPressedMenuItemID).setBackgroundColor(mMenuItems.get(mPressedMenuItemID).getMenuSelectedColor()); invalidate(); } } break; case MotionEvent.ACTION_UP: if(isMenuTogglePressed) { centerRadialColor = Color.WHITE; if(isMenuVisible) { isMenuVisible = false; centerMenuText = openMenuText; } else { isMenuVisible = true; centerMenuText = closeMenuText; } isMenuTogglePressed = false; invalidate(); } if(isMenuItemPressed) { if(mMenuItems.get(mPressedMenuItemID).getCallback() != null) { mMenuItems.get(mPressedMenuItemID).getCallback().onMenuItemPressed(); } mMenuItems.get(mPressedMenuItemID) .setBackgroundColor(mMenuItems.get(mPressedMenuItemID).getMenuNormalColor()); isMenuItemPressed = false; invalidate(); } break; } return true; }

YisSf.png

希望上面的代码有用..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值