Android:加载时显示屏幕
我正在使用 AsyncTask 从服务器获取数据,并希望在加载时显示一个屏幕,如下所示:
private class GetListTask extends AsyncTask {
protected void onPreExecute() {
Intent intent = new Intent();
intent.setClass(Start.this, Wait.class);
startActivity(intent);
}
protected Bitmap doInBackground(Object... args) {
//here i get the data from the server
d = getImageFromURL(Start.valuesArray[Integer.parseInt(Value)][7]);
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
double ratio = (double) bitmap.getWidth() / (double) bitmap.getHeight();
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, width, (int) (width / ratio), true);
return scaled;
}
protected void onPostExecute(Object objResult) {
if (objResult != null && objResult instanceof Bitmap) {
Bitmap result = (Bitmap) objResult;
im.setImageBitmap(result);
}
}
}
现在,在 onPostExecute() 中,我需要再次隐藏此“等待”屏幕,但我该怎么做呢? 感谢您的帮助!
I am using AsyncTask to get data from a server and want to show a Screen while it is loading like this:
private class GetListTask extends AsyncTask {
protected void onPreExecute() {
Intent intent = new Intent();
intent.setClass(Start.this, Wait.class);
startActivity(intent);
}
protected Bitmap doInBackground(Object... args) {
//here i get the data from the server
d = getImageFromURL(Start.valuesArray[Integer.parseInt(Value)][7]);
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
double ratio = (double) bitmap.getWidth() / (double) bitmap.getHeight();
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, width, (int) (width / ratio), true);
return scaled;
}
protected void onPostExecute(Object objResult) {
if (objResult != null && objResult instanceof Bitmap) {
Bitmap result = (Bitmap) objResult;
im.setImageBitmap(result);
}
}
}
Now, in onPostExecute() I need to hide this "Wait" Screen again, but how do I do that?
Thanks for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 PopupDialog 中显示图像并在 onPostExecute 中关闭它,而不是启动不同的活动
instead of starting a different activity you can show your image in a PopupDialog and close it in onPostExecute
使用此布局代替...
现在在
preExecute()
上显示等待的图像视图并隐藏实际布局。并在
postExecute()
上隐藏 imageView 和显示实际布局。Use This Layout instead ...
Now on
preExecute()
show the waiting imageview and hide the actual layout.And on
postExecute()
hide the imageView & show the actual layout.