Android翻译动画 [英] Android Translate Animation
问题描述
我有一个高于底部250dp的ImageView,我想将它移动到底部以上50dp。
I have an ImageView that is 250dp above the bottom and with translate animation i want to move it to 50dp above the bottom.
我知道如何使用翻译动画,但我不知道什么是ToYValue字段。
I know how to use a translate animation, but I don't know what would be the ToYValue field.
代码将是这样的:
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中,这是另一个问题..
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..
关键在于TranslateAnimation文档中的更改一词在Y坐标中更改为在动画开始时申请。
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
这篇关于Android翻译动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!