I am working on android applicaiton. I need to start a second animation when the first animation is going on.
I need to move images one by one after some period of time. I have used framelayout with two imageViews in main.xml.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/ars1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView2">
</ImageView>
<ImageView android:src="@drawable/ars"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1">
</ImageView>
</FrameLayout>
Below is my animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="-100%p"
android:duration="1500" />
</set>
in onc开发者_如何转开发reate method of my activity class, i am doing something like below which is not working.
ImageView imageView1;
ImageView imageView2;
Animation tranOut;
tranOut = AnimationUtils.loadAnimation(this, R.anim.animation);
imageView1 = (ImageView)findViewById(R.id.imageView1);
imageView1.setAnimation(tranOut);
imageView2 = (ImageView)findViewById(R.id.imageView2);
imageView2.setAnimation(tranOut);
Please tell me how can i move the two images one after another.
Thanks Jyoti
Try using animation listener, use onAnimationEnd(), and then start the second one. see the following link for more on animation listener.
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
I have searched a lot and finally did it using ImageSwitcher.
animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="150%p" android:toXDelta="0%p"
android:duration="1500" />
</set>
animation1.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="0%p" android:toXDelta="-150%p"
android:duration="1500" />
</set>
helloworld.java:
public class helloworld extends Activity implements ViewFactory {
public void onCreate(Bundle savedInstanceState) {
Animation rollIn = AnimationUtils.loadAnimation(this, R.anim.animation);
Animation rollOut = AnimationUtils.loadAnimation(this, R.anim.animation1);
final ImageSwitcher iSwitcher = (ImageSwitcher)findViewById(R.id.ImageSwitcher01);
iSwitcher.setFactory(this);
iSwitcher.setInAnimation(rollIn);
iSwitcher.setOutAnimation(rollOut);
iSwitcher.setImageResource(R.drawable.img1);
// TODO: Change the image in ImageSwitcher on end of animation rollIn.
}
Above code is the basic code for implementing this functionality (images move one after another). You can modify this as per your requirement.
精彩评论