0

am creating login and signup in same page with circle reveal animation ,switch the view using a floating action button, it very lag when switching one view to another view,

Login page Contain two relative layout and a floating action button one view for login and other for signup when floating action button click view will switch to another ie login to signup and vise versa.. i achieved but it is too lag how can i make it smooth

in tab(big screen) it works very smoothly(am creating two layout one for mobile and other for tab) can anyone help me.. this is my code..

 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void viewMenu() {

        if (!isOpen) {

//            int x = layoutContent.getRight();
//            int y = layoutContent.getBottom();
            int x = Math.round(fab.getX() + fab.getWidth() / 2);
            int y = Math.round(fab.getY() - fab.getHeight());
            int startRadius = 0;
            int endRadius = (int) Math.hypot(layoutMain.getWidth(), layoutMain.getHeight());

            fab.setBackgroundTintList(ColorStateList.valueOf(ResourcesCompat.getColor(getResources(),android.R.color.white,null)));
            fab.setImageResource(R.drawable.ic_cross);

            Animator anim = ViewAnimationUtils.createCircularReveal(layoutButtons, x, y, startRadius, endRadius);


            anim.setInterpolator(new AccelerateDecelerateInterpolator());
            layoutButtons.setVisibility(View.VISIBLE);
            anim.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {
//                    fst_view.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationEnd(Animator animator) {

                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            });
            anim.start();

            isOpen = true;

        } else {

//            int x = layoutButtons.getRight();
//            int y = layoutButtons.getBottom();
            int x = Math.round(fab.getX() + fab.getWidth() / 2);
            int y = Math.round(fab.getY() + fab.getHeight()/2) - toolbar.getHeight();
            int startRadius = Math.max(layoutContent.getWidth(), layoutContent.getHeight());
            int endRadius = 0;

            fab.setBackgroundTintList(ColorStateList.valueOf(ResourcesCompat.getColor(getResources(),R.color.colorAccent,null)));
            fab.setImageResource(R.drawable.ic_menu_camera);
//            fst_view.setVisibility(View.VISIBLE);
            Animator anim = ViewAnimationUtils.createCircularReveal(layoutButtons, x, y, startRadius, endRadius);


            anim.setInterpolator(new AccelerateDecelerateInterpolator());
            anim.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {

                }

                @Override
                public void onAnimationEnd(Animator animator) {
                    layoutButtons.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            });
            anim.start();

            isOpen = false;
        }

    }
Anushka
  • 1
  • 1

1 Answers1

1

As far as I can see, you could use FastOutLinearInInterpolator() instead of AccelerateDecelerateInterpolator(), and add anim.setDuration() with animation duration you want. And set layoutButtons.setVisibility() to View.INVISIBLE like described here in the bottom of the article.

Furthermore, you can rid of from Math.round() when you calculate view x, y coordinates.

It worked great for my case.

Here is my example code