[英]Loading image while progress bar loads
I want to have an async task that loads images from the drawable folder.我想要一个从 drawable 文件夹加载图像的异步任务。 How could i display a progress bar in another xml?
如何在另一个 xml 中显示进度条? I want to display the images in gallery.
我想在图库中显示图像。
How do I go about doing it?我该怎么做? ** It would be helpful if you use the hello gallery code**
** 如果您使用 hello gallery 代码会很有帮助**
Thanks in advance.提前致谢。
If you whant to show a progress bar, you have to create a globar variable to reference the progress bar.如果您想显示进度条,则必须创建一个全局变量来引用进度条。
ProgressDialog myProgressDialog;
Then, in the asynk task use the default methods to handle the progressBar然后,在 aynk 任务中使用默认方法来处理 progressBar
@Override
protected void onPreExecute()
{
//create the dialog
progressDialog = ProgressDialog.show(getBaseContext(), "Tittle","Description");
};
@Override
protected Void doInBackground(Void... params)
{
//load the image
return null;
}
@Override
protected void onPostExecute(Void result)
{
//dismiss te dialog
progressDialog.dismiss();
};
If you want to use a percent bar you can also use the method如果您想使用百分比栏,您也可以使用该方法
onProgressUpdate()
In async task在异步任务中
send a progressbar(which one you want to update) to asynctask's constructor,In the method doBackground,loading your picture and use method publisProgress(maybe named this,just alt + /),last,updating your progressbar in this method..向 asynctask 的构造函数发送一个进度条(您要更新哪个),在方法 doBackground 中,加载您的图片并使用方法 publisProgress(可能命名为 this,只是 alt + /),最后,在此方法中更新您的进度条..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.