Как перемещать изображения одно за другим в приложении для Android? - PullRequest
0 голосов
/ 09 сентября 2011

Я работаю над приложением для Android.Мне нужно запустить вторую анимацию, когда происходит первая анимация.

Мне нужно перемещать изображения одно за другим через некоторое время.Я использовал framelayout с двумя imageViews в 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>

Ниже приведен мой 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);

Скажите, пожалуйста, как я могу перемещать два изображения одно за другим?

Спасибо, Jyoti

Ответы [ 2 ]

0 голосов
/ 20 сентября 2011

Я много искал и наконец сделал это, используя 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.

}

Выше код является основным кодом для реализации этой функции (изображения перемещаются один за другим).Вы можете изменить это согласно вашему требованию.

0 голосов
/ 09 сентября 2011

Попробуйте использовать слушатель анимации, используйте onAnimationEnd (), а затем запустите второй.см. следующую ссылку для получения дополнительной информации о слушателе анимации.

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

...