加载数据时如何实现progressBar? [英] How to implement progressBar while loading data?
问题描述
我想实现下图所示的progressBar.
I want to implement progressBar like on the picture below.
现在,我已经从片段类中分离出了AsyncTask,并且我使用该AsyncTask来加载数据,并且现在我实现了progressBar对话框,但是我想摆脱它,因为我想制作一个更好的UX
Right now, I have AsyncTask whic is sperated from fragments classes, and I use that AsyncTask to load data, and right now I have implement progressBar dialog, but I want to get rid of that, because I want make a better UX.
我在onPreExecute()方法中显示了ProgressBar对话框,然后在onPostExecute上将其关闭.
I show that ProgressBar dialog in onPreExecute() method, and then dismiss it onPostExecute.
所以,我如何实现背景进度栏,如下图所示
So, how I can implement background Progress bar like on the picture below
推荐答案
Dude,
如果您真的只想要一个进度条,如您发布的图片,则只需将进度条的 indeterminate 属性设置为true即可:)
If you really just want a progress bar like the picture you posted, you can simply set the progress bar indeterminate property to true :)
您可以对代码进行编码,也可以直接在xml上进行编码.
You can eighter do on code or directly on the xml.
在代码中:
yourProgressBar.setIndeterminate(true);
在XML中,只需将属性indeterminate设置为true.
In your XML, just set the attribute indeterminate to true.
以下是一个简单的布局示例:
Here's is a simple layout as an example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true" />
</RelativeLayout>
这篇关于加载数据时如何实现progressBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!