Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth slide image one way

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?

like image 596
falsetto Avatar asked Oct 15 '15 13:10

falsetto


1 Answers

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);
like image 143
falsetto Avatar answered Oct 01 '22 15:10

falsetto