У меня есть некоторый пользовательский класс BitmapStorage, не присоединенный к любому Представлению или безотносительно - служебное. И у меня есть файл born_animation.xml, который содержит <список анимаций> с кадрами анимации:
<animation-list oneshot="true" >
<item drawable="@drawable/frame01" />
<item drawable="@drawable/frame02" />
</animation-list>
Я хочу загрузить анимацию из XML-файла как AnimationDrawable с помощью класса Ресурсов (таким образом, это сделало бы весь парсинг для меня), Битовые массивы извлечения, и поместите их в мой пользовательский класс памяти.
Проблема я имею:
Resources res = context.getResources();
AnimationDrawable drawable = (AnimationDrawable)res.getDrawable(R.drawable.born_animation);
assertTrue( drawable != null ); <= fails! it's null
WTF? Кто-то может объяснить меня это? Прекрасные компиляции кода. Все ресурсы существуют.
Я попробовал иначе - используют ImageView, чтобы сделать парсинг (как описанный в руководстве dev)
ImageView view = new ImageView(context);
view.setBackgroundResource(R.drawable.born_animation);
AnimationDrawable drawable = (AnimationDrawable)view.getBackground();
assertTrue( drawable != null ); <= fails! it's null
Результатами является то же. это возвращает drawable пустой указатель.
Любой hinsts значительно ценился бы, заранее спасибо.
Yay, я нашел причину! :)
Это было мое плохое: у меня не было правильного формата моего файла анимации.xml:
после того, как я исправил эти вещи RES.GetDrawable () начал возвращать правильный экземпляр анимации.
пришлось более точно выглядеть на Resources.notfoundException, и это getcouse () выяснить, что не так:)
Новый
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myprogress"
android:oneshot="false">
<item android:drawable="@drawable/progress1" android:duration="150" />
<item android:drawable="@drawable/progress2" android:duration="150" />
<item android:drawable="@drawable/progress3" android:duration="150" />
</animation-list>
код:
ImageView progress = (ImageView)findViewById(R.id.progress_bar);
if (progress != null) {
progress.setVisibility(View.VISIBLE);
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.setCallback(progress);
frameAnimation.setVisible(true, true);
}
Вид
<ImageView
android:id="@+id/progress_bar"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myprogress" />