【问题标题】:Android circle reveal animation not smoothAndroid圆圈显示动画不流畅
【发布时间】:2018-08-13 08:29:22
【问题描述】:

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

登录页面包含两个相对布局和一个浮动操作按钮 一种用于登录,另一种用于注册 当浮动操作按钮单击视图将切换到另一个,即登录以注册,反之亦然.. 我实现了,但它太滞后了我怎样才能使它顺利

在标签(大屏幕)中它工作得非常顺利(我正在创建两个布局,一个用于移动设备,另一个用于标签) 谁能帮帮我..这是我的代码..

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

    }

【问题讨论】:

  • 您能否改写 ypur 的问题,这样您想要实现的目标会更加明显。另外请尝试提高问题质量,以便其他用户可以理解。
  • 在大多数情况下,主线程上执行的工作太多。
  • 我试过可以吗?我是新来的..
  • 你能帮帮我吗

标签: android animation view android-animation linear-interpolation


【解决方案1】:

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

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

它对我的情况非常有用。

Here 是我的示例代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 2014-10-30
    相关资源
    最近更新 更多