В моем приложении я хочу переопределить внешний вид и состояние индикатора выполнения. По умолчанию используется прямоугольник и загружается анимация. Итак, что я сделал?Android, текущий индикатор анимации не запущен
Первый в res/drawable я создал loadanim.xml (loading01-6 - мои .png изображения).
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:drawable="@drawable/loading01" android:duration="300" />
<item android:drawable="@drawable/loading02" android:duration="300" />
<item android:drawable="@drawable/loading03" android:duration="300" />
<item android:drawable="@drawable/loading04" android:duration="300" />
<item android:drawable="@drawable/loading05" android:duration="300" />
<item android:drawable="@drawable/loading06" android:duration="300" />
</animation-list>
Затем в res \ layout я создал еще один XML-файл с именем layout_loading.xml.
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/blankImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loading01"/>
В коде у меня есть кнопка, которая при нажатии на нее отображается индикатор выполнения. Код:
private ProgressDialog progressBar;
private AnimationDrawable myAnimation;
Button btnCustom1 = (Button) findViewById(R.id.custom1);
btnCustom1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
progressBar = ProgressDialog.show(MainActivity.this, "", "");
progressBar.setContentView(R.layout.layout_loading);
progressBar.setCancelable(true);
final ImageView imageView = (ImageView) progressBar.findViewById(R.id.blankImageView);
imageView.setBackgroundResource(R.drawable.loadinganim);
myAnimation = (AnimationDrawable) imageView.getBackground();
myAnimation.start();
}
});
Проблема заключается в том, когда я нажимаю на кнопку, изображение будет показывать, но там нет анимации. подобный следующий изображение. Скажите, пожалуйста, как я могу запустить анимацию? или где моя вина?
Спасибо, что помогли мне.