Question

I'm fairly new to Droid and I've been beating my head trying to figure out how to create this animation loop, I would like it to look something like this ...

3animatedimages

I've been trying to create 3 back to back translateanimations that slide to the right one by one endlessly. I can get the first imageview to animate like I want it but I'm stumped on what to add to my code to get the other animations to animate behind it as well

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView image1 = (ImageView) findViewById(R.id.nescontroller);
ImageView image2 = (ImageView) findViewById(R.id.segacontroller);
ImageView image3 = (ImageView) findViewById(R.id.pscontroller);

TranslateAnimation anim1 = new TranslateAnimation(0, 500, 0, 0);
anim1.setDuration(2000);
anim1.setRepeatCount(Animation.INFINITE);

image1.startAnimation(anim1);


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

    <ImageView
    android:id="@+id/ee"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/e" />

    <ImageView
    android:id="@+id/dd"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/d" />

    <ImageView
    android:id="@+id/pscontroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/c" />

    <ImageView
    android:id="@+id/segacontroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/b" />

    <ImageView
    android:id="@+id/nescontroller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/a" />
</RelativeLayout>

any help or suggestion would be appreciated

Was it helpful?

Solution

OKAY I'm saddened no one could help me with this but after a month of hapless searching and digging I found a way to do it.

I figured out how to use Animationlistener properly, I've yet to figure out how to start animationlistener initially so I just used a dummy animation to get the loop started which only lasts one millisecond off screen.

I also added in little transition animations so that each new underlapping image shows up at the same time the overlapping image moves off screen instead of having it appear after its completely moved off screen :-)

ImageView image0 = (ImageView) findViewById(R.id.splashimage)
ImageView image1 = (ImageView) findViewById(R.id.nescontroller);
ImageView image2 = (ImageView) findViewById(R.id.segacontroller);
ImageView image3 = (ImageView) findViewById(R.id.pscontroller);

anim0 = new TranslateAnimation(400.0f, 400.0f, 0.0f, 0.0f);
    anim0.setDuration(1);
    img0.startAnimation(anim0);

anim1 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim1.setStartOffset(2000);
    anim1.setDuration(2000);
    anim1.setFillAfter(true);

anim2 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim2.setStartOffset(2000);
    anim2.setDuration(2000);
    anim2.setFillAfter(true);

anim3 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim3.setStartOffset(2000);
    anim3.setDuration(2000);
    anim3.setFillAfter(true);

stationary1 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary1.setDuration(4000);
stationary1.setFillAfter(true);

stationary2 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary2.setDuration(4000);
stationary2.setFillAfter(true);

stationary3 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary3.setDuration(4000);
stationary3.setFillAfter(true);

anim0.setAnimationListener (new AnimationListener() {
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub 
            }
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
            }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img1.startAnimation(anim1);
        img2.startAnimation(stationary1);


    }
});

anim1.setAnimationListener (new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 

        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img2.startAnimation(anim2);
        img3.startAnimation(stationary2);

    }
});

anim2.setAnimationListener(new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 
        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img3.startAnimation(anim3);
        img1.startAnimation(stationary3);

    }
});
anim3.setAnimationListener(new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 
        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img1.startAnimation(anim1);
        img2.startAnimation(stationary1);


    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top