2013-07-08 37 views
1

我正在嘗試使用翻譯動畫和縮放動畫設置動畫,以使視圖從其大小/位置移動到另一個視圖大小/位置。將縮放和翻譯差異化爲視圖間的動畫過渡?

我試圖讓與的getX /的getY或getLocationOnScreen位置喂翻譯動畫,但沒有運氣的第一視圖到第二在動畫的最後匹配:/

(同爲大規模動畫)

任何想法?

+0

我幾乎沒有,但不知何故,翻譯影響從規模樞軸,使得觀點有點「抵消」。 – Tryum

回答

0

明白了......我的問題是我首先應用了翻譯動畫,並且它與縮放動畫的樞軸點有關。

只以下的示例代碼轉換X上

View viewFrom = findViewById(R.id.viewA); 
View viewTo = findViewById(R.id.viewB); 
// Getting delta from center 
int delta = (viewTo.getLeft()+Math.round(viewTo.getWidth()*viewTo.getScaleX()))-(viewFrom.getLeft()+Math.round(viewFrom.getWidth()+viewFrom.getScaleX())); 
float ratio = viewTo.getScaleX()/viewFrom.getScaleX(); 
Animation anim = new ScaleAnimation(1.f, ratio, 1.f, ratio, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
AnimationSet animSet = new AnimationSet(true); 
animSet.setInterpolator(new DecelerateInterpolator()); 
animSet.addAnimation(anim); 
anim = new TranslateAnimation(0, delta, 0, 0); 
animSet.addAnimation(anim); 
animSet.setDuration(500); 
viewFrom.startAnimation(animSet);