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?
Smooth slide image one way
Asked Answered
you can use pager also for this. here is demo codetheory.in/… –
Cannabis
Yeah, the 'proper' way would be to use a ViewPager to swipe images. –
Lefty
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);
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);
There 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. –
Botheration
Though you got answer, try this repository, this will solve all your queries regarding slides and also will add custom animation to your views!
© 2022 - 2024 — McMap. All rights reserved.