Monday, January 30, 2012

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

Create two xml file in anim folder of application...


1)push_left_out.xml



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
 <translate
        android:duration="1000"
        android:fromXDelta="0"
        android:toXDelta="-100%p" />
 <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:toAlpha="1.0" />
</set>


2)push_right_out.xml



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
        android:duration="1000"
        android:fromXDelta="0"
        android:toXDelta="100%p" />
<alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="1.0" />
</set>


In OnCreate() method take the reference of layout or any view's



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


Animation an1, an2;

an1 = AnimationUtils.loadAnimation(this, R.anim.push_right_out);
an2 = AnimationUtils.loadAnimation(this, R.anim.push_left_out);


img.startAnimation(an1);
layout.startAnimation(an2);
In above example the layout will move towards left and imageview towards right...






No comments:

Post a Comment