Android翻译动画



我有一个位于底部上方250dp的ImageView,通过平移动画,我想将其移动到底部上方50dp。

我知道如何使用平移动画,但我不知道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);

您希望fromYValue为0,表示从当前位置开始,toYValue为50,表示向下移动50个像素。请注意,这些值以像素为单位,而不是以dp为单位。如果它必须在dp中,那就是另一个问题了。。

关键是TranslateAnimation文档中的"更改"一词"在动画开始时应用Y坐标的更改"

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

最新更新