2012-03-09 3 views
4

Я использую следующий код, чтобы повернуть изображение на весь экранПоворот изображения Просмотр в андроида непрерывно

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
<rotate 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:duration="500" 
    android:repeatCount="infinite" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    > 
</rotate> 
</set> 

Анимация rotate1 = AnimationUtils.loadAnimation (это, R.anim.rotate_picture); rotate.startAnimation (rotate1);

Макета, который я использую это

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
> 
<ImageView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/loader" 
android:layout_centerInParent="true" 
android:id="@+id/rotate" 
/> 
</RelativeLayout> 

Но остановить 500мс и перезапустить again.But мне нужно повернуть изображение continuously.Without остановить его в middle.How я могу это сделать.

+0

Как выглядит ваш макет? – TryTryAgain

+0

Вы когда-нибудь находили решение? – Zapnologica

ответ

0
//custom_anim.xml 
<?xml version="1.0" encoding="utf-8" ?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <rotate 
     android:fromDegrees="0" 
     android:toDegrees="360" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:duration="2000" /> 
    <alpha 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:duration="2000"> 
    </alpha> 
    <scale 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fromXScale=".1" 
     android:fromYScale=".1" 
     android:toXScale="1.0" 
     android:toYScale="1.0" 
     android:duration="2000" /> 

</set> 


//Oncreate 

Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); 

      imgageview.startAnimation(rotateimage); 
      rotateimage.setAnimationListener(new AnimationListener() { 

       public void onAnimationStart(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       public void onAnimationRepeat(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       public void onAnimationEnd(Animation animation) { 
        // TODO Auto-generated method stub 

        AnimateandSlideShow(); 
       } 
      }); 


//function 
private void AnimateandSlideShow() { 
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); 

      imgageview.startAnimation(rotateimage); 
      rotateimage.setAnimationListener(new AnimationListener() { 

       public void onAnimationStart(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       public void onAnimationRepeat(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       public void onAnimationEnd(Animation animation) { 
        // TODO Auto-generated method stub 

        AnimateandSlideShow(); 
       } 
      }); 
} 
+0

Не работает непрерывно – koti

+0

После того, сколько времени анимация остановится?. –

+0

increse продолжительность в android: duration = "" tag –

0

Я просто попробовал. По какой-то нечетной причине по умолчанию используется AccelerateDecelerateInterpolator. Добавьте android:interpolator="@android:anim/linear_interpolator", и вы получите что-то более полезное.

Однако есть еще маленькая остановка после каждого 500мса, я думаю, что это перезагружает анимацию или у него есть один кадр слишком много (0 = 360)

Вы можете увеличить значения на более длительный срок, чтобы лучше эффект. Попробуйте android:duration="50000" и android:toDegrees="36000".

0

Добавить этот объект в атрибуте циклического сдвига

android:repeatMode="restart" 

Или изменить файл rotate1.xml, удалить набор тегов. Пример:

<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:duration="500" 
    android:repeatCount="infinite" 
    android:pivotX="50%" 
    android:pivotY="50%"> 
</rotate> 
Смежные вопросы