2012-03-13 109 views
1

我想用兩個動作創建動畫。第一個動作:查看前進,第二個動作:查看返回。我爲描述動畫創建了xml,但它不起作用。感謝您的關注。我/anim/move_animation.xmlAndroid動畫。兩個翻譯活動

<?xml version="1.0" encoding="utf-8"?> 
    <set xmlns:android="http://schemas.android.com/apk/res/android" 
       android:interpolator="@android:anim/linear_interpolator"> 
      <translate 
      android:fromYDelta="50%" 
      android:toYDelta="50%" 
      android:fromXDelta="0%" 
      android:toXDelta="50%" 
      android:duration="2000" /> 
     <translate 
      android:startOffset="2000" 
      android:fromYDelta="50%" 
      android:toYDelta="50%" 
      android:fromXDelta="50%" 
      android:toXDelta="0%" 
      android:duration="2000" /> 
    </set> 

活動:

public class TestActivity extends Activity { 
    private LinearLayout LL; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     LL = (LinearLayout) this.findViewById(R.id.MainLayout); 

     Animation anim = AnimationUtils.loadAnimation(this, R.anim.move_animation); 
     LL.startAnimation(anim); 
    } 
} 

佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:id="@+id/MainLayout" > 
    <ImageView 
      android:id="@+id/Icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:background="@drawable/icon" > 
     </ImageView> 
</LinearLayout> 
+0

什麼不起作用。如果您希望我們能夠提供幫助,您可能需要詳細說明。 – FoamyGuy 2012-03-13 20:31:06

+0

做兩個不同的動畫,在彼此之後運行它們,如果問題仍然存在,則意味着動畫的方式存在問題。 – 2012-03-13 20:34:46

+0

@Tim感謝您的評論。我特別創建測試小項目來解決這個問題。我添加了其他文件的主題。 – PihPah 2012-03-13 22:23:02

回答

0

使2個動畫您的動畫。第一個將首先翻譯,第二個動畫將是你的第二個翻譯。 和你setonanimationlistener和onanimationend在它。當第一個結束時你會開始第二個。它會工作的很好