用于上下移动 ImageView 的动画

Deb*_*jee 2 animation android move

我是 Android 动画的新手,搜索了很多关于向上和向下移动 ImageView 的内容,但有很多关于从左到右移动的问题。我找不到可以上下移动的啧啧。谁能告诉我我怎样才能做到这一点?我在这里添加了一些代码,这是我从 YouTube 学到的从左到右移动图像的代码(imga 是 ImageView)-

 Animation img = new TranslateAnimation(Animation.ABSOLUTE, 150, Animation.ABSOLUTE, Animation.ABSOLUTE);
            img.setDuration(3000);
            img.setFillAfter(true);

            imga.startAnimation(img);
Run Code Online (Sandbox Code Playgroud)

Abu*_*suf 5

将此 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>
Run Code Online (Sandbox Code Playgroud)

在 Java 类中:

// Animation
Animation animUpDown;

 // load the animation
animUpDown = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.up_dwon);

  // start the animation
  view.startAnimation(animUpDown);
Run Code Online (Sandbox Code Playgroud)