用于上下移动ImageView的动画

时间:2018-03-24 11:21:37

标签: android animation 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);

2 个答案:

答案 0 :(得分:2)

将此xml用于动画 的动画/ 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);

答案 1 :(得分:1)

你需要知道图像或物体运动背后的逻辑,它将在轴上设置动画,从x到x delta或从y到y delta

  • x = n变量中的值x = -n变量描述图像将移动 从右到左三角洲
  • x = -n变量中的值x = n变量描述图像将移动
    从左到右三角洲
  • y = n变量中的值y = -n变量描述图像将移动 从上到下三角洲
  • y = -n变量中的值到y = n变量描述图像将移动 从底部到顶部delta

下图将带您进入10标准数学 movement graph for the image

注意:此处n被视为DP或顶点的点。