简体   繁体   English

查看 Gallery Intent 上的 ProgressBar

[英]View ProgressBar on Gallery Intent

I'm using these codes to view an image from my application:我正在使用这些代码从我的应用程序中查看图像:

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(imgFile), "image/*");
startActivity(intent);

I have no problem viewing the picture but when the size is a little bit larger, the intent keeps blank until the image is ready to load and show.我查看图片没有问题,但是当尺寸稍大一点时,意图保持空白,直到图像准备好加载和显示。

My question is, how can I show a ProgressBar, or in more advanced way, show a temporary image, before the real image get shown?我的问题是,如何在显示真实图像之前显示 ProgressBar,或者以更高级的方式显示临时图像?

Thanks for the answer.感谢你的回答。

Try Asynctask as shown here:尝试 Asynctask,如下所示:

try{
class test extends AsyncTask{


     TextView tv_per;
     int mprogress;

    Dialog UpdateDialog = new Dialog(ClassContext);

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        mprogress = 0;

        UpdateDialog.setTitle(getResources().getString(R.string.app_name));
        UpdateDialog.setContentView(R.layout.horizontalprogressdialog);
        TextView dialog_message =  (TextView)UpdateDialog.findViewById(R.id.titleTvLeft);
        tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
        dialog_message.setText(getResources().getString(R.string.dialog_retrieving_data));
        dialog_message.setGravity(Gravity.RIGHT);
        UpdateDialog.setCancelable(false);
        UpdateDialog.show();
        super.onPreExecute();
    }



    @Override
    protected void onProgressUpdate(Object... values) {
        // TODO Auto-generated method stub
        ProgressBar update = (ProgressBar)UpdateDialog.findViewById(R.id.horizontalProgressBar);
        update.setProgress((Integer) values[0]);
        int percent =  (Integer) values[0];
        if(percent>=100)
        {
            percent=100;
        }
        tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
         tv_per.setText(""+percent);
    }



    @Override
    protected Object doInBackground(Object... params) {
        // TODO Auto-generated method stub
        //your code of UI operation
}

        super.onPostExecute(result);
        UpdateDialog.dismiss();
    }

 }
 new test().execute(null);

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

Also refer to this link: Fetch data from server and refresh UI when data is fetched?另请参阅此链接: 从服务器获取数据并在获取数据时刷新 UI? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM