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

目前 還沒有找到相關的解決的方法抓狂,如果有高人知道,求指點。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章