我想要一个进度圈而不是进度对话框
我想在加载数据时在我的应用程序中显示进度圆。我有一个活动,从一个活动移动到另一个活动,我正在解析一些 xml 数据,因此暂时在解析完成之前我想显示循环加载效果。
I want to show a progress Circle in my app while loading data. I have an activity and moving from one activity to another I am parsing some xml data so for the time being until the parsing is completed I want to show a circular loading effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用不确定的 ProgressBar 来实现循环加载效果。以下是在 XML 中执行此操作的方法:
您可以将高度和宽度更改为您想要的值。加载完成后,您可以将其可见性更改为 View.INVISIBLE 或 View.GONE
You can use an indeterminate ProgressBar for the circular loading effect. Here is how you do it in XML:
You can change the height and width to be what you want. When you are done loading, you can change it's visibility to View.INVISIBLE or View.GONE
您需要在 res/anim 文件夹中创建动画 xml 文件,并在加载数据时在 ImageView 中调用 startAnimation ,在停止加载数据时调用 stopAnimation 。并将加载图片设置为ImageView,例如:
此 id 代码为圆形动画 xml 文件
You need to create animation xml file in res/anim folder and call startAnimation in your ImageView when you are loading data and stopAnimation when you stop loading data. And set loading image to ImageView, for example:
This id code for circle animation xml file
将此插入两个 View 标签之间
Insert this beetween two View tags
为什么不使用进度条 UI
dan
Why not use the progressbar UI
dan
使用AsyncTask进行加载和解析:
Use AsyncTask for loading and parsing:
就像进度对话框一样,使用动画代替异步任务,并使其在执行前可见并在执行后再次隐藏。
Just as you would the progress dialog, use an animation instead with async task and just make it visible on prexecution and hide it again on post.
要扩展 trgraglia 的答案,您可以创建一个不确定的(行为:循环)进度条并将可见性设置为 false。在 AsyncTask preExecute() 期间,使其可见,并在 AsyncTask onPostExecute() 期间,将其恢复为不可见(前提是您处于同一活动或您可能需要的情况)。这消除了创建动画的需要。
To expand a bit on trgraglia's answer, you could create an indeterminate (behavior: cycle) progress bar and set the visibility to false. During AsyncTask preExecute(), make it visible, and during AsyncTask onPostExecute(), turn it back to invisible (provided you are staying on the same activity or w/e case you may need). This eliminates the need to create an animation.