Android翻译动画

Android翻译动画,android,imageview,translate-animation,Android,Imageview,Translate Animation,我有一个ImageView,它比底部高出250dp,通过平移动画,我想把它移到比底部高出50dp的位置 我知道如何使用平移动画,但我不知道ToYValue字段是什么 代码如下所示: TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0,Animation.ABSOLUTE,250,Animation.ABSOLUTE,5

我有一个ImageView,它比底部高出250dp,通过平移动画,我想把它移到比底部高出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坐标中的更改以在动画开始时应用”中的“更改”一词