2011-11-03 88 views
3

我有一個佈局,看起來像這樣:(沒有箭頭)機器人旋轉動畫

layout

周圍的佈局動物的圖片。 我想製作一個旋轉動畫,以便所有動物都會沿箭頭方向(實際上,它們應該能夠在視圖周圍360°旋轉)方向 並替換彼此的位置。但保持自己的方向 - 以便每個動物將保持站在她的腿,而不是她的頭:-)

我堅持了這個問題2天現在,我不知道如何實現這個

請幫忙嗎? 謝謝, 羅恩

回答

11

你可以手動動畫他們,像遊戲精靈。在

rotate_left.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <rotate 
      android:toDegrees="0" 
      android:fromDegrees="359" 
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:duration="2000" 
      android:repeatCount="infinite" 
      android:interpolator="@android:anim/linear_interpolator" 
      /> 
</set> 

rotate_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <rotate 
      android:toDegrees="359" 
      android:fromDegrees="0" 
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:duration="2000" 
      android:repeatCount="infinite" 
      android:interpolator="@anim/lin" 
      /> 
</set> 

佈局xml文件(只是一個文本框的頂部和底部,你會:另一種選擇,就是反對旋轉的動畫。必須自己實現4個角落;)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
     android:orientation="horizontal"> 
    <FrameLayout 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:id="@+id/outer" 
      > 
     <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:gravity="center"> 
      <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:id="@+id/top" 
        android:text="Top"/> 
      <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:id="@+id/bottom" 
        android:text="Bottom"/> 


     </LinearLayout> 

    </FrameLayout> 

</LinearLayout> 

您的活動:

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.[yourlayout]); 

    findViewById(R.id.outer).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_left)); 
    findViewById(R.id.top).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right)); 
    findViewById(R.id.bottom).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right)); 
} 

出於某種原因,我不能讓旋轉到正確使用線性內插。它不斷加快/放慢速度。可能必須在代碼中這樣做。

+1

以及如何應用動畫?在LinearLayout或FrameLayout上?你可以添加一些代碼嗎? –

+0

啊!!!完全忘了。 –

+0

謝謝!!!!這是工作! –