如何在android中更改进度对话框大小?

时间:2013-10-05 06:58:55

标签: android user-interface

我使用此方法创建进度对话框。

但它不适合屏幕尺寸。我想最小化此进度对话框的大小。

这是我使用的(AsyncTask)代码:

ProgressDialog myPd_bar;

@Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub

            myPd_bar=new ProgressDialog(AppleModles.this);
              //myPd_bar.setMessage("Loading....");
              myPd_bar.setTitle("Please Wait..");
              myPd_bar.setProgressStyle(myPd_bar.STYLE_HORIZONTAL);
              myPd_bar.setProgress(0);
              myPd_bar.setMax(30);
              myPd_bar.show();
              new Thread(new Runnable() {
                   @Override
                    public void run() {
                          // TODO Auto-generated method stub
                          try
                          {
                                while(myPd_bar.getProgress()<=myPd_bar.getMax())
                                {
                                    Thread.sleep(1000);
                                    handle.sendMessage(handle.obtainMessage());
                                      if(myPd_bar.getProgress()==myPd_bar.getMax())
                                      {
                                            myPd_bar.dismiss();
                                      }

                                }
                          }catch(Exception e){}
                    }
              }).start();


            super.onPreExecute();
        }

Handler handle=new Handler(){
                  @Override
                  public void handleMessage(Message msg) {
                        // TODO Auto-generated method stub
                        super.handleMessage(msg);
                        myPd_bar.incrementProgressBy(5);
                  }
            };

有人可以帮我最小化这个进度对话框大小吗?

2 个答案:

答案 0 :(得分:5)

也许这有助于适应屏幕尺寸:

myPd_bar.show();
Window window = myPd_bar.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

答案 1 :(得分:0)

这将解决这个问题,这应该在show

之后编写
progressbar.getWindow().setLayout(width,height);