android - 上下 move ImageView 的动画

标签 android animation move

<分区>

我是 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);

关于android - 上下 move ImageView 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49464064/

相关文章:

android - 在安卓日历中添加事件日期和时间

android - 如何在 android 4.2 中监控传入的短信

Android Studio 步入错误的 sdk 源

c# - WPF Storyboard 动画不闪烁

android - 垂直于屏幕时,在 Y 轴上查看剪辑的旋转动画

android - 如何调用 getSupportFragmentManager() 获取 FragmentManager 实例

android - 动画,在另一个图像上滑动图像

c++ - 编写 move 复制和 move 赋值构造函数的有效方法

c++ - move 语义只是一个浅拷贝并将其他指针设置为空吗?

c++ - 为什么在这种情况下调用 move 构造函数?