I have image which is symmetrical and I want to move it infinitly from right to left smoothly. I tried to use TranslateAnimation but first I have to properly set my image which is quite difficult mainly because this image is using all screen width and I should set negative margins. Are there any other solution? And is there a possibility to move image without moving ImageView?
Asked
Active
Viewed 913 times
16
-
you can use pager also for this. here is demo http://codetheory.in/android-image-slideshow-using-viewpager-pageradapter/ – Sameer Donga Dec 22 '15 at 17:59
-
Yeah, the 'proper' way would be to use a ViewPager to swipe images. – Muz Dec 23 '15 at 08:07
3 Answers
13
Finally I made it by my own and the solution is to put 2 images on each other and then measure screen width and use 2 TranslateAnimation, one from screen width to 0 and second one from 0 to -screen width:
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);

falsetto
- 789
- 2
- 11
- 35
2
I think this is what you are trying to do:
TranslateAnimation anim = new TranslateAnimation(0, -1000, 0, 0);
anim.setDuration(1500);
anim.setFillAfter(true);
anim.setRepeatCount(0);
anim.setInterpolator(this, Android.Resource.Animation.LinearInterpolator);
Edit:
at the end don't forget imageView.startAnimation(anim);

arsena
- 1,935
- 19
- 36
-
1There are few problems with this solution, it can show blank space when image is moved too much and I have to set negative margins to make it working. – falsetto Oct 19 '15 at 08:38