如何在android中执行doInBackground()时显示动画(如应用程序的标识)

时间:2014-05-02 05:42:44

标签: android android-asynctask jquery-animate

我想在执行Async Task的doInBackground()方法时显示动画应用徽标而不是进度对话框或进度条。

请参阅Expedia Android App的参考资料..

请帮帮我。提前谢谢......

2 个答案:

答案 0 :(得分:1)

You should use custom dialog in  onPreExecute()



Dialog mDialog = new Dialog(mContext,
                android.R.style.Theme_Translucent_NoTitleBar);
        mDialog.setContentView(R.layout.progressbar);
        mDialog.setCancelable(false);
        mDialog.show();`enter code here`


<>>>....This is layout of you custom dialogbar........<<<<<<<<<<<

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="150dip"
    android:layout_height="150dip"
    android:layout_gravity="center"
    android:background="@drawable/progressbar_shap"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Please Wait..."
         android:layout_centerInParent="true"
        android:textStyle="bold" />

    <ProgressBar
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/my_progress_indetermine" >
    </ProgressBar>

</RelativeLayout>


<...................Giving shape to dialog  progressbar_shap................>

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/shape_my" >

    <stroke
        android:width="2dp"
        android:color="#636161" />

    <padding
        android:bottom="20dp"
        android:left="20dp"
        android:right="20dp"
        android:top="20dp" />

    <corners android:radius="24dp" />

    <solid android:color="#88000000" />

</shape>

<.................. my_progress_indetermine .................>

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/please_wait"
        android:pivotX="50%"
        android:pivotY="50%" />

答案 1 :(得分:0)

如Rank指出

        @Override
        protected void onPreExecute() {
            //do animation stuff here
            super.onPreExecute();
        }

然后

protected void onPostExecute(Object result) {
        //end animation here
        super.onPostExecute();  
        }