2011-09-09 22 views
0

我正在开发android应用程序。当第一个动画正在进行时,我需要开始第二个动画。如何在Android应用程序中一个接一个地移动图像?

我需要在一段时间后逐一移动图像。我在main.xml中使用了两个imageViews的framelayout。

<?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> 

下面是我的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> 
在我的活动类的onCreate方法

,我在做类似下面这是行不通的。

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); 

请告诉我如何一个接一个地移动这两个图像。

由于 乔蒂

回答

0

尝试使用动画监听器,使用onAnimationEnd(),然后启动第二个。有关动画侦听器的更多信息,请参阅以下链接。

http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html

+0

感谢您的回复。但是当第一个图像移动时,我必须开始第二个图像。所以我需要在第一个图像的动画开始时,而不是在第一个动画结束时开始第二个图像的动画。请看看你能否帮忙。 – Jyoti

0

我寻觅了很多,最后它使用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. 

} 

上面的代码是为实现该功能的基本代码(移动图像相继)。您可以根据您的要求进行修改。

相关问题