0

我在运行时使用 asychtask 加载 textview 值和图像视图,这需要时间,我不想在整个屏幕上显示 progressDialog。相反,我想要一个小的进度条来代替 textview 和 image view。我怎样才能达到同样的效果。可能吗??在某些应用程序中,我也看到了同样的情况。

谢谢

4

2 回答 2

1

这是你可以做的。ProgressBar可以作为视图添加到布局中,因此只需将其添加为图像视图和文本视图顶部的视图(使用说FrameLayout),一旦你有了数据,你就可以设置ProgressViewtoINVISIBLE或的可见性GONE

的 javadoc 页面ProgressBar也有您可以使用的代码示例。

于 2012-11-19T07:42:10.040 回答
1

是的,您可以使用扩展Dialog类的自定义对话框

import android.app.Dialog;
import android.content.Context;
import android.widget.ProgressBar;
import android.widget.RelativeLayout.LayoutParams;



public class MyProgressDialog extends Dialog {

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message) {
        return show(context, title, message, false);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate) {
        return show(context, title, message, indeterminate, false, null);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate, boolean cancelable) {
        return show(context, title, message, indeterminate, cancelable, null);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate,
            boolean cancelable, OnCancelListener cancelListener) {
        MyProgressDialog dialog = new MyProgressDialog(context);
        dialog.setTitle(title);

        dialog.setCancelable(cancelable);
        dialog.setOnCancelListener(cancelListener);
        /* The next line will add the ProgressBar to the dialog. */
        dialog.addContentView(new ProgressBar(context), new LayoutParams(40,40));
        dialog.show();

        return dialog;
    }

    public MyProgressDialog(Context context) {
        super(context, R.style.NewDialog);
    }
}

在您的活动中,只需像这样调用即可显示:

 MyProgressDialog dialog=MyProgressDialog.show(this, null,null);

解雇也照常dialog.dismiss()。您可以在 style.xml 中指定属性

于 2012-11-19T07:36:52.350 回答