Я создал настраиваемый диалог "Прогресс загрузки". И его работа хорошо.
Я вращаю 12 квадратных изображений. Вот один из них.
Но когда я хочу использовать его с AsynTask, анимация не работает.
Мой примерный код ниже.
Деятельность, где я начинаю загрузку... Анимация и остановка.
MainActivity.java
public class MainActivity extends Activity {
AnimationDrawable loadingViewAnim;
TextView loadigText;
ImageView loadigIcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadigText = (TextView) findViewById(R.id.textView1);
loadigText.setText("Loading...");
loadigText.setVisibility(View.GONE);
loadigIcon = (ImageView) findViewById(R.id.imageView1);
loadigIcon.setVisibility(View.GONE);
loadigIcon.setBackgroundResource(R.anim.progress_animation_white);
loadingViewAnim = (AnimationDrawable) loadigIcon.getBackground();
}
//When User Touch on Screen The Loading... Animation Starts With Image Rotation
//If I start below code in AsynTask onPreExecute method it doesn't work
public boolean onTouchEvent(MotionEvent event)
{
loadigText.setVisibility(View.VISIBLE);
loadigIcon.setVisibility(View.VISIBLE);
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
loadingViewAnim.start();
return true;
}
return super.onTouchEvent(event);
}
}
XML-макет с помощью простого текста и изображения для диалогового окна "Прогресс".
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/progress_sm_w01" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Loading..."
android:textColor="#ffffff"
android:textSize="12sp" />
</LinearLayout>
Анимационный список с 12 изображениями Я вращаюсь с углом и продолжительностью времени
progress_animation_white.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/progress_sm_w01" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w02" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w03" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w04" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w05" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w06" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w07" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w08" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w09" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w10" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w11" android:duration="50" />
<item android:drawable="@drawable/progress_sm_w12" android:duration="50" />
</animation-list>
Вот результат загрузки экрана.
Мой вопрос: все равно, чтобы достичь той же анимации загрузки с AsynTask.
Ваша небольшая помощь будет оценена.