I want to add animation so that my imageview slide towards the left,leave the screen and enter from the right ,sliding back to its original position. I tried doing something like this ..
<translate
android:duration="1000"
android:fromXDelta="0"
android:toXDelta="-100%p" />
<translate
android:startOffset="1000"
android:duration="1000"
android:fromXDelta="100%p"
android:toXDelta="0" />
But the animation is not as per my wish.. Can anyone help me out
Edit: Okay so what you are trying to do is a pain in the a** (ye another one of those android things that should have been simple)! Having two animations after each other just doesn't pan out too well on earlier versions of android. On never versions you can use animationset from api lvl 11. Example here. Alternatively I'd go with a simpler animation.
Here is how to do slide in/out for activity (old answer):
Slide in left activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime"/>
Slide in right activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime"/>
Slide out left activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="@android:integer/config_shortAnimTime" />
Slide out right activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="100%p"
android:duration="@android:integer/config_shortAnimTime" />
Example usage:
Intent intent = new Intent(this, YourNewActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
Example usage on back:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
super.onBackPressed();
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
}
return super.onKeyDown(keyCode, event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With