0

i have an image and i animate it to move from left to right according to the layout width().it worked but not in the first time that i open my activity,only after i pushed back from another activity -the animation started. here is the relevant piece in my code:

protected void onResume(){
super.onResume();
    sMineAnimatior();

}

protected void onStart(){
    super.onStart();


}
protected void onPause(){
    super.onPause();


}

public void sMineAnimatior(){
    ObjectAnimator   bombAnim=ObjectAnimator.ofFloat(bombV,"translationX",0,mainLayout.getWidth());
    bombAnim.setDuration(5000);
    bombAnim.setRepeatCount(Animation.INFINITE);
    bombAnim.setTarget(bombV);
    bombAnim.start();
}
demianr
  • 39
  • 8

1 Answers1

0

Probably mainLayout.getWidth() returns 0, because the view hasn't been measured yet. Use one of the techniques described here to make sure you don't call too early.

Community
  • 1
  • 1
kar
  • 741
  • 6
  • 16