2014-06-23 44 views
0

onPostExecute()我想顯示一些動畫加載使用android.But中使用asynctask即時通訊無法顯示我期待的動畫,更多我無法取消動畫以及。 任何人都可以幫助我解決這個問題。無法取消動畫加載在android

感謝您的寶貴時間!..

Show_AnimatedLoading.java

ImageView imageView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    imageView=(ImageView) findViewById(R.id.imageView1); 

    CustomLoad task = new CustomLoad(); 
    task.execute(); 
} 

public class CustomLoad extends AsyncTask<Void, Void, Void> 
{ 

    @Override 
    protected void onPreExecute() { 
    // TODO Auto-generated method stub 

     Show_animation(); 


    } 

    private void Show_animation() { 
    // TODO Auto-generated method stub 
     Animation a = AnimationUtils.loadAnimation(Show_AnimatedLoading.this, R.anim.progress_anim); 
     a.setDuration(2000); 
     imageView.startAnimation(a); 


     a.setInterpolator(new Interpolator() 
     { 
      private final int frameCount = 50; 

      @Override 
      public float getInterpolation(float input) 
      { 
       return (float)Math.floor(input*frameCount)/frameCount; 
      } 
     }); 
} 

@Override 
    protected Void doInBackground(Void... params) 
    { 
    // TODO Auto-generated method stub 
    return null; 

    } 

    @Override 
    protected void onPostExecute(Void result) { 
    // TODO Auto-generated method stub 

     imageView.clearAnimation(); 

    } 
} 

Progress.xml

<?xml version="1.0" encoding="utf-8"?> 
<rotate 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromDegrees="0" 
android:toDegrees="360" 
android:pivotX="50%" 
android:pivotY="50%" 
android:repeatCount="infinite" /> 

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#000000"> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:contentDescription="@string/app_name" 
    android:src="@drawable/transp_load" /> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:contentDescription="@string/app_name" 
    android:src="@drawable/pc_logo_load" /></RelativeLayout>  
+0

「但是我無法顯示其即時通訊期待的動畫」,你有什麼期待? –

+0

即時通訊設法旋轉一個圖像 – prabu

回答

1

就我所見,您的AsyncTask沒有任何後臺操作。因此,在你開始動畫的「預執行」之後,你清除動畫的地方開始「Post execute」。你沒有看到任何東西是很正常的。嘗試添加一些後臺操作。

試試這個一出來,

final Handler handler = new Handler(); 

    // TODO 
    // Pre execute. 

    new Thread(new Runnable() { 

     @Override 
     public void run() { 
      // TODO 
      // Background operation. 


      handler.postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        // TODO 
        // Post Execute. 

       } 
      }, 3000); 
     } 
    }).start(); 
+0

但是,如果沒有在doInBackground()意味着然後onPostExecute()應該執行正確?這意味着加載選項應該完全打開和關閉?但上述情況並非如此 – prabu