安卓翻译动画

5

我有一个ImageView,它距离底部250dp,并且使用translate动画时,我想将其移动到距离底部50dp的位置。

我知道如何使用translate动画,但我不知道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);
1个回答

2
您需要一个fromYValue为0,表示从当前位置开始,以及一个toYValue为50,表示向下移动50个像素。请注意,这些值是以像素为单位的,而不是dp。如果必须使用dp,那就是另外一个问题了。
关键在于TranslateAnimation文档中的“change”一词,“动画开始时要应用的Y坐标变化”。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接