以一种方式平滑幻灯片图像

Smooth slide image one way

我有一个对称的图像,我想从右向左平滑地无限移动它。我尝试使用 TranslateAnimation,但首先我必须正确设置我的图像,这非常困难,主要是因为该图像使用了所有屏幕宽度,我应该设置负边距。还有其他解决办法吗?是否可以在不移动 ImageView 的情况下移动图像?

我想这就是你想要做的:

        TranslateAnimation anim = new TranslateAnimation(0, -1000, 0, 0);
        anim.setDuration(1500);
        anim.setFillAfter(true);
        anim.setRepeatCount(0);
        anim.setInterpolator(this, Android.Resource.Animation.LinearInterpolator);

编辑: 最后别忘了imageView.startAnimation(anim);

最后我自己做了,解决方案是将 2 个图像放在一起,然后测量屏幕宽度并使用 2 个 TranslateAnimation,一个从屏幕宽度到 0,第二个从 0 到 - 屏幕宽度:

    TranslateAnimation anim = new TranslateAnimation(0, -screenWidth, 0, 0);
    TranslateAnimation anim2 = new TranslateAnimation(screenWidth, 0, 0, 0);
    anim.setDuration(5000);
    anim.setRepeatCount(Animation.INFINITE);
    anim.setInterpolator(new LinearInterpolator());
    anim2.setDuration(5000);
    anim2.setRepeatCount(Animation.INFINITE);
    anim2.setInterpolator(new LinearInterpolator());
    backgroundOverlayImage.startAnimation(anim);
    backgroundOverlayImage2.startAnimation(anim2);

虽然你得到了答案,try 这个存储库,这将解决你关于幻灯片的所有查询,并且还会将自定义动画添加到你的视图中!