【问题标题】:code random animation left android代码随机动画离开android
【发布时间】:2014-07-22 12:15:59
【问题描述】:
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 

我想要随机左动画

【问题讨论】:

  • 如果你想留下随机动画然后创建一个随机 int 改变这样的偏移量:new TranslateAnimation(0.0f, random *1552.0f,0.0f, 0.0f);
  • 我想要随机左动画向右移动

标签: android animation random startapp tree-left-right


【解决方案1】:

如果您只想制作一个随机的 xDelta,那么您可以使用如下代码:

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

它将产生 0 到 1552 之间的随机 xDelta

【讨论】:

    猜你喜欢
    • 2014-02-08
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2021-09-01
    • 1970-01-01
    相关资源
    最近更新 更多