我有一张对称的图片,想要让它平滑地从右到左无限移动。我尝试使用TranslateAnimation,但是首先我必须正确设置我的图片,这相当困难,因为该图片使用了整个屏幕宽度,我应该设置负边距。是否有其他解决方案?而且是否有可能在不移动ImageView的情况下移动图片?
我有一张对称的图片,想要让它平滑地从右到左无限移动。我尝试使用TranslateAnimation,但是首先我必须正确设置我的图片,这相当困难,因为该图片使用了整个屏幕宽度,我应该设置负边距。是否有其他解决方案?而且是否有可能在不移动ImageView的情况下移动图片?
最终我自己解决了这个问题,解决方法是将两张图片重叠放置,然后测量屏幕宽度并使用两个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);
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);