2011-11-03 173 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

谢谢!!!!这是工作! –