Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.1 kB
4
Indexable
Never
public static void slideView(View view,
                                 int currentHeight,
                                 int newHeight) {
        ValueAnimator slideAnimator = ValueAnimator
                .ofInt(currentHeight, newHeight)
                .setDuration(1000);
        slideAnimator.addUpdateListener(animation1 -> {
            view.getLayoutParams().height = (Integer) animation1.getAnimatedValue();
            view.requestLayout();
        });
        ValueAnimator fadeAnimator = ValueAnimator
                .ofInt(0, 100)
                .setDuration(300);
        fadeAnimator.setInterpolator(new AccelerateInterpolator());
        fadeAnimator.addUpdateListener(value -> {
            int alpha = 100 - (Integer) value.getAnimatedValue();
            view.setAlpha(alpha / 100f);
        });
        qrScanAnimationSet = new AnimatorSet();
        qrScanAnimationSet.setInterpolator(new AccelerateDecelerateInterpolator());
        qrScanAnimationSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                float rotation = view.getRotation();
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
                if (rotation == 0) {
                    layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.clearRect);
                    layoutParams.addRule(RelativeLayout.ALIGN_TOP, 0);
                } else {
                    layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, 0);
                    layoutParams.addRule(RelativeLayout.ALIGN_TOP, R.id.clearRect);
                }
                view.setLayoutParams(layoutParams);
                view.setRotation(rotation != 0 ? 0 : 180);
                view.setAlpha(1f);
                qrScanAnimationSet.setStartDelay(0);
                qrScanAnimationSet.start();
            }
        });
        qrScanAnimationSet.play(fadeAnimator).after(slideAnimator);
        qrScanAnimationSet.setStartDelay(500);
        qrScanAnimationSet.start();

    }
Leave a Comment