code random animation left android

369 Views Asked by At
TranslateAnimation animation = new TranslateAnimation(0.0f, 1552.0f,0.0f, 0.0f);        //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)
    `animation.setDuration(2000);`  // animation duration 
    animation.setRepeatCount(100);  // animation repeat count
    animation.setRepeatMode(1);   // repeat animation (left to right, right to left )
    animation.setFillAfter(true);      
    pro.startAnimation(animation);
    progress.startAnimation(animation);  // start animation 

I want random left animation

1

There are 1 best solutions below

0
On

If you just want to make a random xDelta then you may use code like this:

Random randomGenerator = new Random(system.currentTimeMillis());
TranslateAnimation animation = new TranslateAnimation(0.0f, randomGenerator.nextFloat() * 1552.0f,0.0f, 0.0f);

It will produce random xDelta between 0 and 1552