如何不断地使用翻译动画的Andr​​oid移动图像上下? [英] How to move image up and down continuously using translate animation in android?

查看:145
本文介绍了如何不断地使用翻译动画的Andr​​oid移动图像上下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功做了一面动画使用翻译动画意味着图像变为从顶部到底部。这里是code:

I have successfully done one side animation using Translate Animation means the image goes from top to the bottom. Here is the code:

private ImageView mScanner;
private Animation mAnimation;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mScanner = (ImageView)findViewById(R.id.Scanner);

    mAnimation = new TranslateAnimation(0, 0, 0, 500);
    mAnimation.setDuration(10000);
    mAnimation.setFillAfter(true);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    mScanner.setAnimation(mAnimation);
    mScanner.setVisibility(View.VISIBLE);
}

现在我想,当图像到达屏幕的底部,就应该开始移动回顶端。我该怎么办呢?

Now I want that when image reaches to the bottom of the screen, it should start moving back to the top. How can I do that?

注:完成反向模式。请参阅code。但现在的问题是,它从底部移动到顶部时,叶线。就像附加的图像。如何删除此行?

Note: Done the reverse mode. Please see the code. But now problem is that, it leaves lines when moving from bottom to top. Like the attached image. How to remove this lines?

推荐答案

根据该修改您的code:

Modify your code according to this:

   mScanner.setVisibility(View.VISIBLE);
   mAnimation = new TranslateAnimation(
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 1.0f);
   mAnimation.setDuration(10000);
   mAnimation.setRepeatCount(-1);
   mAnimation.setRepeatMode(Animation.REVERSE);
   mAnimation.setInterpolator(new LinearInterpolator());
   mScanner.setAnimation(mAnimation);

而且使用XML,而不是图像。请参阅下面的code和把它放在你的的ImageView SRC。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <solid android:color="#0000FF"/>
    <size android:width="480dp"
        android:height="10dp"/>
    <corners android:radius="1dp"/>
    <stroke android:width="3dp"
        android:color="#000000"/>
</shape>

我希望它会帮助你。

I hope it will help you.

这篇关于如何不断地使用翻译动画的Andr​​oid移动图像上下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆