title: Dynamically move animation on left or right android
body: <p>Hi i am new in android animation i have image of octopus that moves in layout by XML animation<br>
  and i have two flags images of different countries one flag is right on side and one is left on side now i want to move octopus automatically on one side of flag and the movement every<br>
  time will be different mean some time movement will be on left side and some time movement on 
  right side now how can i do that anyone can give good idea. 
  Below is my code ............. XML code for animation </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"
  android:fillAfter="true"
  android:interpolator="@android:anim/linear_interpolator" &gt;
  
  &lt;!-- Use startOffset to give delay between animations --&gt;
  
  
  &lt;!-- Move --&gt;
  &lt;translate
      android:duration="2500"
      android:fillAfter="true"
      android:fromXDelta="0%p"
      android:startOffset="300"
      android:toXDelta="25%p" /&gt;
  &lt;translate
      android:duration="2500"
      android:fillAfter="true"
      android:fromYDelta="0%p"
      android:startOffset="2800"
      android:toYDelta="50%p" /&gt;
  &lt;translate
      android:duration="2500"
      android:fillAfter="true"
      android:fromXDelta="0%p"
      android:startOffset="5300"
      android:toXDelta="-25%p" /&gt;
  &lt;translate
      android:duration="2500"
      android:fillAfter="true"
      android:fromYDelta="0%p"
      android:startOffset="7800"
      android:toYDelta="-50%p" /&gt;
  
  &lt;!-- Rotate 360 degrees --&gt;
  &lt;rotate
      android:duration="2000"
      android:fromDegrees="0"
      android:interpolator="@android:anim/cycle_interpolator"
      android:pivotX="25%"
      android:pivotY="50%"
      android:startOffset="10300"
      android:repeatMode="restart"
      android:toDegrees="180" /&gt;
  
  &lt;/set&gt;
  </code></pre>
  
  <p>here is java code to access that file </p>
  
  <pre><code>Animation fadein_anim;
  ImageView animimagej, imageView;// imageView Button and animimagej is octopus image 
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  animimagej = (ImageView) findViewById(R.id.animimage);
      imageView = (ImageView) findViewById(R.id.iv);
  fadein_anim = AnimationUtils.loadAnimation(getApplicationContext(),
              R.animator.sequence);
      fadein_anim.setAnimationListener(this);
      imageView.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              animimagej.setVisibility(View.VISIBLE);
  
              animimagej.startAnimation(fadein_anim);
  
          }
      });
  }
  public void onAnimationEnd(Animation animation) {
      // TODO Auto-generated method stub
  }
  
  @Override
  public void onAnimationRepeat(Animation animation) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onAnimationStart(Animation animation) {
      // TODO Auto-generated method stub
  
  }
   }
  </code></pre>