Android-如何使用另一个布局作为进度条

时间:2014-05-13 05:28:21

标签: android progressdialog android-progressbar

我在很多应用中都看过这个,他们没有使用ProgressDialog,因为它不允许我们在应用中做任何事情。我不想要那个。 我已经在另一个应用程序中看到了它,而不是ProgressDialog,它们使ui显示进度条,我们也可以做其他工作,例如整个ui成为进度条,何时成为进度条。完成后,主要的ui加载。我认为当激活进度时它们会使用另一种布局,当它完成时,它会恢复主要布局。 我做了这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="79dp"
        android:src="@drawable/load_more" />
   <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/loading"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

我想知道我该怎么做?

非常感谢。

1 个答案:

答案 0 :(得分:2)

有很多方法可以实现这一目标。我看到你了一个方向。

您可以制作Custom Dialog并使用Inflater加载此布局,并将布局设置为Dialog。喜欢

LayoutInflater factory = LayoutInflater.from(Activity.this);
View DialogView = factory.inflate(R.layout.custom_progress_layout, null);

Dialog main_dialog = new Dialog(Activity.this,R.style.Theme_Dialog);
main_dialog.setContentView(DialogView);

progressBar=(ProgressBar)DialogView.findViewById(R.id.progressBar1);
main_dialog.setCancelable(false);
main_dialog.setCanceledOnTouchOutside(false);
progressBar.setProgress(0);
progressBar.setMax(100);
main_dialog.show();

当您的进度完成后,使用dismiss

main_dialog.dismiss();此对话框

同样在此布局中,您可以使用某些TextView显示进度文本和进度。

<强>输出:

enter image description here