Android圈显示动画不流畅

问题描述 投票:0回答:1

我在同一页面创建登录和注册圈子显示动画,使用浮动操作按钮切换视图,将一个视图切换到另一个视图时非常滞后,

登录页面包含两个相对布局和一个浮动操作按钮一个用于登录的视图和另一个用于注册的视图,当浮动操作按钮单击视图将切换到另一个时,即登录注册,反之亦然..我实现但是它太滞后我怎么能做到平滑

在标签(大屏幕)它工作非常顺利(我创建两个布局一个用于移动和其他用于标签)任何人都可以帮助我..这是我的代码..

 @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;
        }

    }
android animation view android-animation linear-interpolation
1个回答
0
投票

据我所知,你可以使用FastOutLinearInInterpolator()而不是AccelerateDecelerateInterpolator(),并添加你想要的动画持续时间的anim.setDuration()。并将layoutButtons.setVisibility()设置为View.INVISIBLE,如article底部所述。

此外,在计算视图x,y坐标时,可以摆脱Math.round()

它对我的案子非常有用。

Here是我的示例代码

© www.soinside.com 2019 - 2024. All rights reserved.