Android中一个动画应用于两个View中不同步的问题

将一个同一个动画应用于两个不同的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


其中有部分人的回答如下:



Won't this cause them to be out of sync (not essential here), especially the ones that are started later? –  Matthew  Feb 9 at 19:58
 
Not really. Basically what happens is when you use startAnimation on 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 call invalidate() 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

目前 还没有找到相关的解决的方法抓狂,如果有高人知道,求指点。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值