您可以使用AsyncTask异步加载图像
只需将与图像加载相关的代码放在doInBackground方法中,并尝试设置进度条或进度对话框之类的指示器,以便在加载开始时开始显示对话框或进度条,完成后使用onPostExecute方法中的处理程序关闭对话框
示例代码:
class SomeClass extends Activity {
protected ProgressDialog pd ;
protected Handler handler = new Handler(){
@Override
public void handleMessage(int what){
if(pd.isShowing())
pd.dismiss();
}
.....
class LoadImageTask extends AsyncTask<URL, Integer, Long> {
protected void onPreExecute(Long result) {
pd = ProgressDialog.show(getContext(),"Title","Message");
}
protected Long doInBackground(URL... urls) {
//Load IMAGEs code
return totalSize;
}
protected void onPostExecute(Long result) {
//finish loadiing images
handler .sendEmptyMessage(0);
}
}
}
我希望这会对你有所帮助