将一个同一个动画应用于两个不同的View中,想让两个View同时向一个方向移动相同的距离。关键代码如下:
Animation topAnimation = new TranslateAnimation(0, 0, 0, -heightOfTopTrans);
topAnimation.setDuration(durationMillis);
// topAnimation.setInterpolator(this, anim.accelerate_interpolator);
topAnimation.setFillAfter(true);
mTopLayout.startAnimation(topAnimation);
mGridView.startAnimation(topAnimation);
但是事实上于理论的相反,从目前的效果来看,mTopLayout要比mGridView的动画开始的慢,感觉就是先开始的后执行。
为什么会出现这种情况?在网上进行相关搜索后,发现也有人遇到同样的问题,但是没有给出解决方案。
在下面的网页中找到了一些相关的信息:http://stackoverflow.com/questions/9217305/single-animation-multiple-views
其中有部分人的回答如下:
目前 还没有找到相关的解决的方法
,如果有高人知道,求指点。
尝试将同一动画同时应用于两个View上,使两者同时移动相同距离,但实际效果显示其中一个View动画启动较慢。讨论了可能的原因及社区反馈。
3340







startAnimationon a view, it starts invalidating itself until it's reached the desired location. When you call it on all the views at once, they'll all callinvalidate()on themselves, then on the next drawing pass each view will be drawn in their next frame. Since you're calling all this on the UI thread anyway, none of the animations will start until you've returned from that method. NOTE: Using the pre-Honeycomb animation framework merely moves the visual portion of the view. The user won't be able to click on it.– DeeV Feb 9 at 20:10