Android仿闲鱼发布弹簧动画
仿闲鱼发布的弹簧动画显示弹框,效果还不错
一、思路:
用SpringAnimation动画
二、效果图:
看视频更直观点:
Android开发案例分享仿闲鱼发布弹簧动画
三、关键代码:
public class MoodPublishSelectDialog {private Context mContext;private AlertDialog dialog;private ConstraintLayout clMain;private DrawableCenterTextView mLlMoodSelectText;private DrawableCenterTextView mLlMoodSelectPhoto;private DrawableCenterTextView mLlMoodSelectVideo;private ImageView mIvMoodSelectClose;public MoodPublishSelectDialog(Context mContext) {this.mContext = mContext;dialog = new AlertDialog.Builder(mContext, R.style.mydialog).setCancelable(false).create();dialog.show();final Window window = dialog.getWindow();window.setContentView(R.layout.layout_mood_publish_select);window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);clMain = window.findViewById(R.id.cl_publish_select);mLlMoodSelectText = window.findViewById(R.id.dctv_mood_select_text);mLlMoodSelectPhoto = window.findViewById(R.id.dctv_mood_select_photo);mLlMoodSelectVideo = window.findViewById(R.id.dctv_mood_select_video);mIvMoodSelectClose = window.findViewById(R.id.iv_mood_select_close);setShapeRoundAndEdge(clMain, 0,0, mContext.getResources().getColor(R.color.white),new float[]{dp2px(mContext,12),dp2px(mContext,12),dp2px(mContext,12),dp2px(mContext,12),0,0,0,0});springAnim(mLlMoodSelectText, 3000f);springAnim(mLlMoodSelectPhoto, 3800f);springAnim(mLlMoodSelectVideo, 4600f);mIvMoodSelectClose.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});}public static void setShapeRoundAndEdge(View view, int lineWide, int lineColor, int solidColor, float[] corner){GradientDrawable gradientDrawable = new GradientDrawable();if(lineWide != 0 && lineColor != 0){gradientDrawable.setStroke(lineWide,lineColor);}if(solidColor != 0){gradientDrawable.setColor(solidColor);}gradientDrawable.setCornerRadii(corner);view.setBackground(gradientDrawable);}public static int dp2px(Context context, float dpValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}/*** @param view* @param translationY desc:弹簧动画,带透明度效果* create by cong on 2018/4/3 10:39*/public static void springAnim(final View view, float translationY) {if (view != null) {view.setTranslationY(translationY);view.setAlpha(0f);final SpringAnimation leftLogoAnimY = new SpringAnimation(view, SpringAnimation.TRANSLATION_Y, 0);leftLogoAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);leftLogoAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);leftLogoAnimY.setStartVelocity(-2000);
四、项目demo源码结构图:
有问题或者需要完整源码demo的私信我,我每天都看私信的