我为自定义进度条创建了示例程序。它正在工作,但我遇到的问题是进度条没有设置在屏幕中间。
我必须先显示列表的查看项目,然后才能显示进度条。
这里我的完整代码如下: -
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<com.wang.avi.AVLoadingIndicatorView
android:layout_width="wrap_content"
android:background="#000"
android:layout_gravity="center"
android:layout_height="wrap_content"
style="@style/AVLoadingIndicatorView.Large"
app:indicatorName="BallPulseIndicator"
android:id="@+id/avi"
/>
<ListView
android:id="@+id/visitor_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
main.java
private AVLoadingIndicatorView avi;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_rorder, container, false);
getActivity().setTitle("Order");
String indicator=getActivity().getIntent().getStringExtra("indicator");
avi= (AVLoadingIndicatorView)view.findViewById(R.id.avi);
avi.setIndicator(indicator);
new DownloadJSON().execute();
return view;
}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
avi.show();
// avi.setVisibility(View.VISIBLE);
/*
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Please Wait");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
*/
}
@Override
protected Void doInBackground(Void... args) {
try {
}
@Override
protected void onPostExecute(Void args) {
// mProgressDialog.dismiss();
avi.hide();
}
}
}
喜欢这个我试过但它不起作用请帮助我。
答案 0 :(得分:1)
尝试将RelativeLayout
用作ListView
和AVLoadingIndicatorView
的父级,并将layout_centerInParent
的{{1}}属性设置为true:
AVLoadingIndicatorView
答案 1 :(得分:0)
只需您可以使用进度对话框。示例如下:
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(getActivity(), "", "Please Wait ", true, false);
}
@Override
protected void onPostExecute(Void result) {
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
}