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>
「但是我無法顯示其即時通訊期待的動畫」,你有什麼期待? –
即時通訊設法旋轉一個圖像 – prabu