java 安卓加载动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10242585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android loading animation
提问by Streetboy
I am searching for some info on how to create loading animation in android. Is it possible to create this animation that i could call this animation in one thread and end in other ?
我正在寻找有关如何在 android 中创建加载动画的一些信息。是否可以创建这个动画,我可以在一个线程中调用这个动画并在另一个线程中结束?
I seeking for this:
我寻求这个:
回答by Dinesh
Try below Code
试试下面的代码
ProgressDialog for showing:
ProgressDialog 用于显示:
ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
mDialog.setMessage("Loading...");
mDialog.setCancelable(false);
mDialog.show();
After cancel ProgressDialog below code:
取消 ProgressDialog 下面的代码后:
mdialog.dismiss();
回答by WarrenFaith
This is basically done with an AsyncTaskand a ProgressDialog(Using spinner style) that is started and dismissed by the AsyncTask.
这基本上是通过AsyncTask和由AsyncTask启动和解除的ProgressDialog(使用微调器样式)完成的。
回答by EvilDuck
You can not start/end ProgressDialog from any thread other that UI thread. In it's simplest for you would want to use AsyncTask methods onPreExecute onPostExecute. But I would be careful with that.
您不能从 UI 线程以外的任何线程启动/结束 ProgressDialog。在最简单的情况下,您希望使用 AsyncTask 方法 onPreExecute onPostExecute。但我会小心的。
- you don't want to lose a reference to dialog from async task (user changes orientation or rotates the screen). So you want to keep WeakReference to dialog
- If you're doing serious loading worj, I'd recomment using Service for it and listening for service callbacks (like broadcasts) to control dialog. This will also allow you separate Activity lifecycle from background work.
- 您不想从异步任务中丢失对对话框的引用(用户更改方向或旋转屏幕)。所以你想保持对对话框的 WeakReference
- 如果您正在认真加载 worj,我建议您使用 Service 并监听服务回调(如广播)来控制对话框。这也将允许您将 Activity 生命周期与后台工作分开。