2015-09-17 5 views
3
<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="300dp" 
     android:layout_height="300dp" 
     android:src="@drawable/zaid1" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

У меня есть изображение в середине действия, как бы я сделал это, чтобы он вращался на 360 градусов бесконечно?Как заставить изображение постоянно вращаться?

ответ

15

Попробуйте использовать RotateAnimation:

RotateAnimation rotateAnimation = new RotateAnimation(0, 360f, 
    Animation.RELATIVE_TO_SELF, 0.5f, 
    Animation.RELATIVE_TO_SELF, 0.5f); 

rotateAnimation.setInterpolator(new LinearInterpolator()); 
rotateAnimation.setDuration(500); 
rotateAnimation.setRepeatCount(Animation.INFINITE); 

findViewById(R.id.imageView1).startAnimation(rotateAnimation); 
0

Или XML путь. Создайте папку «anim» в папке res. Создайте xml-файл, назовите его, как хотите. Здесь вы можете определить свою анимацию.

Внутри XML файл положить:

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

Теперь вы просто загрузить анимации:

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.your_xml_name); 

, а затем запустить его:

findViewById(R.id.imageView1).startAnimation(rotation); 
Смежные вопросы