2013-10-12 18 views
0

我是相當新的Droid和我一直在跳動我的頭試圖找出如何創建這個動畫循環,我希望它看起來像這樣...卡住如何使我的機器人動畫連續

3animatedimages

我一直在試圖創建3個背靠背該幻燈片由一個連續正確的translateanimations。我能拿到第一的ImageView動畫像我想,但我很爲難什麼就添加到我的代碼來獲取其他動畫背後動畫以及

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

任何幫助或建議,將不勝感激

回答

0

OKAY我很難過,沒有人可以幫助我,但經過一個月的不幸尋找和挖掘,我找到了一個方法來做到這一點。

我想出瞭如何正確使用Animationlistener,我還沒有弄清楚如何最初啓動animationlistener,所以我只使用了一個虛擬動畫來啓動只持續1毫秒的屏幕開始的循環。

我還小過渡動畫添加,使得每個新的背墊圖像同時重疊圖像移離屏幕而不是具有其完全移動離開屏幕之後出現:-)

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


    } 
}); 
顯示出來