Smooth slide image one way
Asked Answered
B

3

16

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?

Botheration answered 15/10, 2015 at 13:29 Comment(2)
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
B
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);
Botheration answered 18/12, 2015 at 9:24 Comment(0)
C
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);

Chatham answered 15/10, 2015 at 14:49 Comment(1)
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
C
0

Though you got answer, try this repository, this will solve all your queries regarding slides and also will add custom animation to your views!

Preview

Carpogonium answered 24/12, 2015 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.