/ / Ako v aplikácii pre Android posúvať obrázky jeden za druhým? - android, android-animácia

Ako presunúť obrázky jeden po druhom v aplikácii pre Android? - android, android-animácie

Pracujem na aplikácii pre Android. Keď sa deje prvá animácia, musím spustiť druhú animáciu.

Po určitej dobe potrebujem presunúť obrázky jeden po druhom. Použil som framelayout s dvoma imageViews v 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>

Nižšie je uvedený môj 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>

v oncreate metóde mojej triedy aktivity robím niečo ako nižšie, čo nefunguje.

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

Prosím, povedzte mi, ako môžem presunúť dva obrázky jeden za druhým.

Vďaka Jyoti

odpovede:

0 pre odpoveď č. 1

Skúste použiť poslucháč animácií, použite onAnimationEnd () a potom spustite druhý. pre poslucháčov animácií nájdete nasledujúci odkaz.

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


0 pre odpoveď č. 2

Veľa som hľadal a nakoniec som to urobil pomocou nástroja 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.

}

Vyššie uvedený kód je základný kód na implementáciu tejto funkcie (obrázky sa pohybujú jeden za druhým). Môžete to upraviť podľa svojich požiadaviek.