-1

我写了下面的方法来显示进度条,但是由白框四舍五入的进度条适合屏幕宽度,我不知道为什么。

public void showProgressBar() {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    ProgressBar pbar = new ProgressBar(activity, null,
            android.R.attr.progressBarStyleLargeInverse);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(30, 50);
    pbar.setLayoutParams(params);
    builder.setView(pbar);
    builder.setCancelable(true);
    progressBar = builder.create();
    progressBar.show();
}

执行上述方法时,进度如图所示。

进度条问题 我该如何解决这个问题?

4

2 回答 2

1

您应该使用 aProgressDialog并且不,它不适合屏幕宽度。

ProgressDialog pd=new ProgressDialog(activity);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setIndeterminate(true);
        pd.setCancelable(false);
        pd.show();

这应该给你你想要的。

做这个:

ProgressDialog pd;//declare as a global variable
public void showProgressBar() {
pd=new ProgressDialog(activity);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setIndeterminate(true);
        pd.setCancelable(false);
        pd.show();

}

以后ProgressDialog不管你想去哪里。

于 2013-04-12T18:47:32.277 回答
0

我用愚蠢的方式解决了它,但它对我很好。

public abstract class AbstractScreen implements IActivity {

protected Response response;
protected FragmentActivity activity;
private CustomProgressDialog progress;

public AbstractScreen(FragmentActivity activity) {
this.activity = activity;
}

public abstract void loadScreen();

@Override
public void preExecution() {
// TODO Auto-generated method stub

}

@Override
public void postExecution(Response response) {
// TODO Auto-generated method stub

}

 public void showProgressBar() {


 progress = new CustomProgressDialog(activity);
 progress.show();
 }

 public void closeProgress() {
 progress.dismiss();
 }

 public FragmentActivity getActivity() {
 return activity;
 }

 private class CustomProgressDialog extends Dialog {

 private Context context;

 public CustomProgressDialog(Context context) {
 super(context);
 this.context = context;
 loadScreen();
 }

 public void loadScreen() {

 requestWindowFeature(Window.FEATURE_NO_TITLE);
 setContentView(R.layout.progress);
 setCancelable(false);

 }

 }
 }

也添加这个布局文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_marginRight="-7dp"
>

<ProgressBar
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 style="?android:attr/progressBarStyleLarge"
 android:id="@+id/progressbar"
 android:layout_gravity="center_horizontal"
 android:max="100"
 />
 </LinearLayout>
于 2013-04-13T10:04:57.827 回答