我有一個加載自定義ImageView的活動(https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/example/touch/TouchImageView.java)。在onCreate中,我使用setImageBitmap來顯示一個巨大的圖像(4Mb ...)。如何知道ImageView何時完成加載圖像?
問題是此活動需要4秒才能顯示,但沒有可以放置在AsyncTask中的阻止方法。我的意思是我所有的活動代碼都被執行,但活動僅在圖像加載時纔會出現,並且我不知道何時完成。
我想要做的是在Activity加載它時顯示ProgressDialog,並在完成時顯示它。
我該如何解決這個問題?這是一些代碼。
希望你能理解我的問題,這很難解釋。謝謝 !
carte.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<loki.test.lokitest.affichage.TouchImageView
android:id="@+id/image"
android:src="@drawable/loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:id="@+id/bouton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/textBouton"/>
</RelativeLayout>
CarteActivity.java(一個誰需要4秒)
public class CarteActivity extends Activity implements OnClickListener{
private Group groupe;
private String android_id;
private ConnexionServeur serveur;
private TouchImageView vue;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("Loki","onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.carte);
findViewById(R.id.bouton).setOnClickListener(this);
vue = ((TouchImageView)findViewById(R.id.image));
vue.setImageBitmap(Singleton.getInstance().getImage());
groupe = Singleton.getInstance().getGroupe();
android_id = Singleton.getInstance().getAndroid_id();
serveur = Singleton.getInstance().getServeur();
if(groupe != null)
groupe.afficherGroupe(vue);
}
}
EDIT:圖像裝入 :
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.myImage);
但我不認爲這是這個代碼我需要時間,它已經完成,當我使用setImageBitmap。我無法弄清楚需要花費那麼多時間,但我想知道是否可以訪問。
你可以發佈用於加載圖像的代碼嗎?函數getImage()中的代碼。 – Bobbake4
我加了代碼。 – Oyashiro
@Oyashiro確實發佈了您找到的解決方案 – Javanator