我是 Android 中动画的新手,搜索了很多关于在 ImageView 上上下 move 的内容,但是有很多关于从左到右 move 的问题。我找不到可以上下 move 的tut。谁能告诉我如何实现这一目标?
我在这里添加一些代码,我从 YouTube 上学到了从左到右 move 图像(imga 是 ImageView)-
Animation img = new TranslateAnimation(Animation.ABSOLUTE, 150, Animation.ABSOLUTE, Animation.ABSOLUTE);
img.setDuration(3000);
img.setFillAfter(true);
imga.startAnimation(img);
将此 xml 用于动画
anim/up_down.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<!-- Move -->
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="0%p"
android:toYDelta="70%p" />
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="0%p"
android:startOffset="800"
android:toYDelta="-70%p" />
</set>
在 Java 类中:
// Animation
Animation animUpDown;
// load the animation
animUpDown = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.up_dwon);
// start the animation
view.startAnimation(animUpDown);