Monday, January 30, 2012

Animate the layout's towards right and left i.e moving towards inside?

Create the  file reverse_left.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="1000"
        android:fromXDelta="-100%p"
        android:toXDelta="0" />

    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:toAlpha="1.0" />

</set>

and reverse_right.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="1000"
        android:fromXDelta="100%p"
        android:toXDelta="0" />

    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:toAlpha="1.0" />

</set>


And just use it for your imageview and layout.....


img = (ImageView) findViewById(R.id.imageView1);
layout = (LinearLayout) findViewById(R.id.lin);



Animation rightAnimation = AnimationUtils.loadAnimation(this, R.anim.reverse_right);
Animation leftAnimation = AnimationUtils.loadAnimation(this, R.anim.reverse_left);

img.startAnimation(rightAnimation);
layout.startAnimation(leftAnimation);


No comments:

Post a Comment