анимация в андроид

1

Я создал файл animation.xml, в котором я добавил свой материал фреймовой анимации, но он не работает. Я назвал 5this в своем классе активности следующим образом....

animation = (ImageView)findViewById(R.id.imageAnimation);
        animation.setBackgroundResource(R.drawable.animation);      // the frame-by-frame animation defined as a xml file within the drawable folder
        AnimationDrawable frameAnimation = 
                (AnimationDrawable) animation.getBackground();
            frameAnimation.start();

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

Файл animation.xmal

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false">

    <item android:drawable="@drawable/anatomy_5" android:duration="50" />
    <item android:drawable="@drawable/anatomy_6" android:duration="50" />
    <item android:drawable="@drawable/anatomy_7" android:duration="50" />
    <item android:drawable="@drawable/anatomy_8" android:duration="50" />
    <item android:drawable="@drawable/anatomy_9" android:duration="50" />
    <item android:drawable="@drawable/anatomy_10" android:duration="50" />
    <item android:drawable="@drawable/anatomy_11" android:duration="50" />
    <item android:drawable="@drawable/anatomy_12" android:duration="50" />
    <item android:drawable="@drawable/anatomy_13" android:duration="50" />
    <item android:drawable="@drawable/anatomy_14" android:duration="50" />
    <item android:drawable="@drawable/anatomy_15" android:duration="50" />
    <item android:drawable="@drawable/anatomy_16" android:duration="50" />
    <item android:drawable="@drawable/anatomy_17" android:duration="50" />
    <item android:drawable="@drawable/anatomy_18" android:duration="50" />
    <item android:drawable="@drawable/anatomy_19" android:duration="50" />
    <item android:drawable="@drawable/anatomy_20" android:duration="50" />
    <item android:drawable="@drawable/anatomy_21" android:duration="50" />
    <item android:drawable="@drawable/anatomy_22" android:duration="50" />
    <item android:drawable="@drawable/anatomy_23" android:duration="50" />
    <item android:drawable="@drawable/anatomy_24" android:duration="50" />
    <item android:drawable="@drawable/anatomy_25" android:duration="50" />
    <item android:drawable="@drawable/anatomy_26" android:duration="50" />
    <item android:drawable="@drawable/anatomy_27" android:duration="50" />
    <item android:drawable="@drawable/anatomy_28" android:duration="50" />
    <item android:drawable="@drawable/anatomy_29" android:duration="50" />
    <item android:drawable="@drawable/anatomy_30" android:duration="50" />
    <item android:drawable="@drawable/anatomy_31" android:duration="50" />
    <item android:drawable="@drawable/anatomy_32" android:duration="50" />
    <item android:drawable="@drawable/anatomy_33" android:duration="50" />
    <item android:drawable="@drawable/anatomy_34" android:duration="50" />
    <item android:drawable="@drawable/anatomy_35" android:duration="50" />
    <item android:drawable="@drawable/anatomy_36" android:duration="50" />
    <item android:drawable="@drawable/anatomy_37" android:duration="50" />
    <item android:drawable="@drawable/anatomy_38" android:duration="50" />
    <item android:drawable="@drawable/anatomy_39" android:duration="50" />
    <item android:drawable="@drawable/anatomy_40" android:duration="50" />
    <item android:drawable="@drawable/anatomy_41" android:duration="50" />
    <item android:drawable="@drawable/anatomy_42" android:duration="50" />
    <item android:drawable="@drawable/anatomy_43" android:duration="50" />
    <item android:drawable="@drawable/anatomy_44" android:duration="50" />
    <item android:drawable="@drawable/anatomy_45" android:duration="50" />
    <item android:drawable="@drawable/anatomy_46" android:duration="50" />
    <item android:drawable="@drawable/anatomy_47" android:duration="50" />
    <item android:drawable="@drawable/anatomy_48" android:duration="50" />
    <item android:drawable="@drawable/anatomy_49" android:duration="50" />

</animation-list>
Теги:
animation

3 ответа

2
Лучший ответ

попробуй это

положить animation.xml файл в anim папке

Простая анимация

Animation rAnim = AnimationUtils.loadAnimation(your_context, R.anim.animation);
animation.startAnimation(rAnim);

где animation - ваше imageview

Обновить

Анимированная анимация

    AnimationDrawable rocketAnimation;

    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
      rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
      rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
       final Thread thread = new Thread(new Runnable() 
    {
    @Override
    public void run() 
    { wait(1000);      
     activity.runOnUiThread(new Runnable() {@Override public void run()
    {
     rocketAnimation.start();
    }});
     }
});
thread.start();

    }

    public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        rocketAnimation.start();
        return true;
      }
      return super.onTouchEvent(event);
    }
  • 0
    что такое акт? Вы можете объяснить?
  • 0
    проверь мой ответ
Показать ещё 20 комментариев
3

Как показано на рисунке внизу страницы с возможностью рисования анимации:

Важно отметить, что метод start(), вызываемый в AnimationDrawable, не может быть вызван во время метода onCreate() вашей Activity, потому что AnimationDrawable еще не полностью привязан к окну. Если вы хотите немедленно воспроизвести анимацию, не требуя взаимодействия, вы можете вызвать ее из метода onWindowFocusChanged() в своей Activity, который вызывается, когда Android переключит ваше окно в фокус.

Надеюсь, это поможет..;) Приветствия

  • 1
    Это один из лучших моментов, приведенных здесь. Не запускать анимацию во время OnCreate() !
1

сделать папку Анит в разрешении и поставить animation.xml в папке Anim и чем использовать этот способ

 Animation anim = AnimationUtils.loadAnimation(this,R.anim.animation);
 imageview.setAnimation(anim); 
 or
 imageview.startAnimation(anim);
  • 2
    это вызывает у меня исключение java.lang.RuntimeException: неизвестное имя анимации: список анимаций

Ещё вопросы

Сообщество Overcoder
Наверх
Меню