动感的Sheet(选择器)AndroidSweetSheet_安卓5.0 Action Sheet
程序员文章站
2021-11-23 19:34:58
...
分享一个Sheet选择器、AndroidSweetSheet一个富有动感的 Sheet(选择器)、效果是使用Android5.0 的动画特效、弹性动画、非常好看、Demo是采用Android Studio 开发的、如果没有安装Android Studio的哥们可以下载查看效果、效果图如下
SweetViewshow()
public void show() { mStatus=Status.STATUS_SMOOTH_UP; if(mAnimationListener != null) { mAnimationListener.onStart(); this.postDelayed(new Runnable() { @Override public void run() { mAnimationListener.onContentShow(); } }, 600); } ValueAnimator valueAnimator=ValueAnimator.ofInt(0, mMaxArcHeight); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); mArcHeight = value; if (value == mMaxArcHeight) { duang(); } invalidate(); } }); valueAnimator.setDuration(800); valueAnimator.setInterpolator(new AccelerateInterpolator()); valueAnimator.start(); }
SweetViewduang()
public void duang(){ mStatus=Status.STATUS_DOWN; ValueAnimator valueAnimator=ValueAnimator.ofInt(mMaxArcHeight,0); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mArcHeight = (int) animation.getAnimatedValue(); invalidate(); } }); valueAnimator.addListener(new SimpleAnimationListener() { @Override public void onAnimationEnd(Animator animation) { if (mAnimationListener != null) { mAnimationListener.onEnd(); } } }); valueAnimator.setDuration(500); valueAnimator.setInterpolator(new OvershootInterpolator(4f)); valueAnimator.start(); }
SweetViewdrawBG()
private void drawBG(Canvas canvas) { mPath.reset(); int currentPointY=0; switch (mStatus){ case NONE: currentPointY = mMaxArcHeight; break; case STATUS_SMOOTH_UP: case STATUS_UP: currentPointY=getHeight()-(int) ((getHeight()-mMaxArcHeight)* Math.min(1,(mArcHeight-mMaxArcHeight /4 )* 2.0 / mMaxArcHeight * 1.3)); break; case STATUS_DOWN: currentPointY = mMaxArcHeight; break; } mPath.moveTo(0, currentPointY); mPath.quadTo(getWidth() / 2, currentPointY - mArcHeight, getWidth(), currentPointY); mPath.lineTo(getWidth(), getHeight()); mPath.lineTo(0, getHeight()); mPath.lineTo(0, currentPointY); canvas.drawPath(mPath, mPaint); }
最后给贴上Demo的源代码、希望对大家有用、有兴趣的哥们可以下载看看
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1pJsu6RD 密码: xkma
上一篇: 设计模式-责任链模式