解决方案 »

  1.   

    是在显示计算结果前,提示用户“正在计算...”这样的消息吗?然后计算出结果,提示消失吗?这样的话你可以写一个progressDialog对话框,选择圆形的那个风格...
      

  2.   

    把你的计算代码交给服务或者线程处理,结果用广播返回,开始处理时UI显示提示信息,UI监听结果,处理完后更新UI界面。
      

  3.   

    了解下异步线程Asynctask的用法,应该能帮到你
      

  4.   

    计算部分,放到线程里去,另外,UI线程显示progressDialog,在计算完后,线程通过handler通知关闭progressDialog
      

  5.   

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageView=(ImageView)findViewById(R.id.picture);
    button=(Button)findViewById(R.id.button);
    dialog=new ProgressDialog(this);
    dialog.setTitle("提示");
    dialog.setMessage("图片下载中");
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setCancelable(false);
    }
    public class myTask extends AsyncTask<String,Integer,Bitmap>{
            //表示任务操作之前的操作
    @Override
    protected void onPreExecute(){
    super.onPreExecute();
    dialog.show();
    }
    @Override
    protected void onProgressUpdate(Integer... values) {
    // TODO Auto-generated method stub
    super.onProgressUpdate(values);
    dialog.setProgress(values[0]);
    }
    //主要执行耗时操作
    @Override
    protected Bitmap doInBackground(String... params) {
    // TODO Auto-generated method stub

    ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
    InputStream inputStream=null;
    Bitmap bitmap=null;
    try {
    HttpClient httpClient=new DefaultHttpClient();
    HttpGet httpGet=new HttpGet(params[0]);
    HttpResponse httpResponse=httpClient.execute(httpGet);
    if(httpResponse.getStatusLine().getStatusCode()==200){
    inputStream=httpResponse.getEntity().getContent();
    long file_length=httpResponse.getEntity().getContentLength();
    int len=0;
    byte[] data=new byte[1024];
    int total_length=0;
    while((len=inputStream.read(data))!=-1){
    total_length+=len;
    int value=(int)((total_length/(float)file_length)*100);
    publishProgress(value);
    outputStream.write(data,0,len);
    }
    byte[]result=outputStream.toByteArray();
    bitmap=BitmapFactory.decodeByteArray(result, 0, result.length);
    }

    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }finally{
    if(inputStream!=null){
    try {
    inputStream.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    return bitmap;
    }
    //跟新UI界面
    @Override
    protected void onPostExecute(Bitmap result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);
    imageView.setImageBitmap(result);
    dialog.dismiss();
    }


    }
    我这个是横向的,你可以选择圆形的,而且我这个可以根据网络下载的,显示进度。你可以根据自己的需要改一下,把你的计算操作放到doInBackground里面就可以了。