2013-11-17 2 views
0

Я хочу создать простое изображение, которое вращается на 20 градусов (например, часы) и на 20 градусов назад. У меня есть этот простой макет:Повернуть изображение просмотрено

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/witewall_3"> 

    <ImageView 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:id="@+id/pet" 
     android:src="@drawable/animal" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

и эту деятельность

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

     ImageView image=(ImageView) findViewById(R.id.pet); 

     RotateAnimation anim = new RotateAnimation(0f, 0f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); 

     anim.setInterpolator(new LinearInterpolator()); 
     anim.setRepeatCount(Animation.INFINITE); 
     anim.setDuration(700); 

     image.startAnimation(anim); 
    } 
} 

, что я делаю неправильно и мое изображение не вращается? я пробовал много учебников и nothink работал :(

ответ

1

Вы вращающиеся от 0 до 0 градусов. Первый параметр является от степени и второго параметра класса RotationAnimation является конечной точкой градусов.

RotateAnimation anim = new RotateAnimation(0f, 20f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); 

Если вы хотите продолжать вращаться двадцать также необходимо обеспечить первый параметр, который является градусами, из которого он будет анимировать.

RotateAnimation anim = new RotateAnimation(20f, 40f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); 
RotateAnimation anim = new RotateAnimation(40f, 60f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); 
0
set degree from 0 to 360 when you define RatateAnimation() 

RotateAnimation rotateAnimation = new RotateAnimation(0, 360); 
rotateAnimation.setDuration(5000); 
rotateAnimation.setInterpolator(new LinearInterpolator()); 
rotateAnimation.setRepeatMode(Animation.INFINITE); 
image.setAnimation(rotateAnimation); 
+0

Хотя этот ответ только для кода может решить эту проблему, необходимо больше объяснений, чтобы помочь будущим пользователям сайта понять, как применить это решение к их ситуации. Пожалуйста, подумайте над тем, чтобы добавить свой ответ. –

Смежные вопросы