2013-08-20 95 views
1

我想製作一個包含多個項目的動畫列表,每個項目包含一個旋轉標籤。什麼是形成它的正確方法?還有其他方法可以做到這一點嗎?這是我的代碼:如何用多個旋轉標籤正確形成動畫xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="true" > 
    <rotate 
     android:interpolator="@android:anim/linear_interpolator" 
     android:repeatMode="restart" 
     android:fromDegrees="0" 
     android:toDegrees="50" 
     android:pivotX="301" 
     android:pivotY="334" 
     android:duration="1000" 
     android:startOffset="0" 
    /> 



    <rotate 
     android:interpolator="@android:anim/linear_interpolator" 
     android:repeatMode="restart" 
     android:fromDegrees="50" 
     android:toDegrees="20" 
     android:pivotX="301" 
     android:pivotY="334" 
     android:duration="859" 
     android:startOffset="0" 
    /> 

</set> 

我希望這個XML重複,當它結束。請幫忙。

回答

2

請拆分旋轉到2動畫XML文件 「rotate_0_50.xml」 & 「rotate_50_20.xml」,並嘗試下面的代碼:

final Animation anim0_50 = AnimationUtils.loadAnimation(this, R.anim.rotate_0_50); 
final Animation anim50_20 = AnimationUtils.loadAnimation(this, R.anim.rotate_50_20); 

final View animView = findViewById(R.id.anim_view) 
anim0_50.setAnimationListener(new AnimationListener() {   
    @Override 
    public void onAnimationStart(Animation animation) {}    
    @Override 
    public void onAnimationRepeat(Animation animation) {}   
    @Override 
    public void onAnimationEnd(Animation animation) { 
     animView.startAnimation(anim50_20);       
    } 
}); 

anim50_20.setAnimationListener(new AnimationListener() {    
    @Override 
    public void onAnimationStart(Animation animation) {}    
    @Override 
    public void onAnimationRepeat(Animation animation) {}   
    @Override 
    public void onAnimationEnd(Animation animation) { 
     animView.startAnimation(anim0_50);       
    } 
}); 

animView.startAnimation(anim0_50); 
+1

由於這個工程。是不是有辦法在一個xml中做到這一點? – mremremre1