问题
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