2012-03-29 255 views
5

我有一个ImageView,它的底部是250dp,翻译动画我想将它移动到底部以上的50dp。Android翻译动画

我知道如何使用翻译动画,但我不知道什么是ToYValue字段。

代码西港岛线是这样的:

TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0,Animation.ABSOLUTE,250,Animation.ABSOLUTE,50); 
translate.setDuration(1000); 
translate.reset(); 
translate.setFillAfter(true); 
iv.clearAnimation(); 
iv.startAnimation(translate); 

回答

2

你想要的0 fromYValue,从那里目前是开始的意思,和50 toYValue,这意味着移动50个像素下来。请注意,这些值以像素为单位,而不是dp。如果它必须在dp中,那么这是另一个问题。

关键是在TranslateAnimation文档中的“change”一词中“在Y坐标中更改以在动画开始时应用”。

http://developer.android.com/reference/android/view/animation/TranslateAnimation.html