Hi i am new in android animation i have image of octopus that moves in layout by XML animation
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
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
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<!-- Use startOffset to give delay between animations -->
<!-- Move -->
<translate
android:duration="2500"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="300"
android:toXDelta="25%p" />
<translate
android:duration="2500"
android:fillAfter="true"
android:fromYDelta="0%p"
android:startOffset="2800"
android:toYDelta="50%p" />
<translate
android:duration="2500"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="5300"
android:toXDelta="-25%p" />
<translate
android:duration="2500"
android:fillAfter="true"
android:fromYDelta="0%p"
android:startOffset="7800"
android:toYDelta="-50%p" />
<!-- Rotate 360 degrees -->
<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" />
</set>
here is java code to access that file
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
}
}