How to make a right to left animation in a layout
This code may help you.
Animation Left slide:
Create a file under res/anim/anim_left
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
Animation Right slide:
Create a file under res/anim/anim_right
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
Use it in Activity as:
Animation rightSwipe = AnimationUtils.loadAnimation(this, R.anim.anim_right);
<view>.startAnimation(rightSwipe);
public void slidefromRightToLeft(View view) {
TranslateAnimation animate;
if (view.getHeight() == 0) {
main_layout.getHeight(); // parent layout
animate = new TranslateAnimation(main_layout.getWidth()/2,
0, 0, 0);
} else {
animate = new TranslateAnimation(view.getWidth(),0, 0, 0); // View for animation
}
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
view.setVisibility(View.VISIBLE); // Change visibility VISIBLE or GONE
}