Android Translate Animation

試著忘記壹切 提交于 2019-12-07 06:54:57

问题


I have an ImageView that is 250dp above the bottom and with translate animation i want to move it to 50dp above the bottom.

I know how to use a translate animation, but I don't know what would be the ToYValue field.

The code wil be something like this:

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:


You want a fromYValue of 0, meaning start from where it is currently, and a toYValue of 50, meaning move 50 pixels down. Note that these values are in pixels, not dp. If it has to be in dp, that is a whole other question..

The key is in the word "change" from the TranslateAnimation documentation "Change in Y coordinate to apply at the start of the animation."

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



来源:https://stackoverflow.com/questions/9927931/android-translate-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!