简体   繁体   English

Android-View.animate跳过

[英]Android - View.animate skipping

I'm working on animating a View from within a GridLayout. 我正在从GridLayout内为View设置动画。 When I access the view from the View.OnClickListener onClick(View view) method the animation runs smoothly. 当我从View.OnClickListener onClick(View view)方法访问视图时,动画运行平稳。

However, when I get Views via gridLayout.getChildAt(i) the animation skips straight to the ending position. 但是,当我通过gridLayout.getChildAt(i)获取视图时,动画会直接跳到结束位置。

                view.animate()
                    .translationX(viewAnimation.xTransform)
                    .translationY(viewAnimation.yTransform)
                    .setDuration(200)
                    .setListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animator) {
                            //Code
                        }

                        @Override
                        public void onAnimationEnd(Animator animator) {
                            if (reloadGrid)
                              //Code
                            else
                                animate(viewAnimations);
                        }

                        //Other methods here
                    });

I'm really unsure as to why when the View is passed as a parameter it animates fine, however otherwise it skips. 我真的不确定为什么将View作为参数传递时动画效果很好,但是否则会跳过。

Any advice would be great! 任何建议都很好!

Edit I have also checked and the difference between the 2 'View' objects is one has mDrawable set and one doesn't. 编辑我也检查过,两个“视图”对象之间的区别是一个具有mDrawable设置,一个没有。 I believe this could be the cause? 我相信这可能是原因吗?

I'm not really sure why this solves the problem, however accessing each View within the GridLayout via findViewById(i) seems to work, and then allow the animation to run smoothly. 我不太确定为什么能解决这个问题,但是似乎可以通过findViewById(i)访问GridLayout中的每个View,然后让动画平稳运行。

This took way too long to figure out. 这花了很长时间才弄清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM