简体   繁体   中英

How to show a progress bar for a layout until the SmartImageView is loaded

How can I trigger spinner.setVisibility(View.GONE); after SmartImageView is loaded?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    mUrl = getIntent().getStringExtra(URL);
    Image = (SmartImageView) findViewById(R.id.ivP);
    final ProgressBar spinner = (ProgressBar) findViewById(R.id.loading);
    spinner.setVisibility(View.VISIBLE);
    Image.setImageUrl(mUrl);
    spinner.setVisibility(View.GONE);
}

You can have OnCompleteListener() on smartImageView

So use it like this.

// start the progress dialog

    smartImageView.setImageUrl("Your image url", new OnCompleteListener() {

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

                    // end the progress dialog

                }
            });

I'm not familiar with SmartImageView, but what you probably want is to set a place holder image into the SmartImageView and then replace it after the image is done downloading. alternately you want to display a loading view over the imageView while you download the image, and get a listener that will let you know when it's done downloading.

Take a look at the Picasso library as it does exactly that and it is extremely easy to use (1 line) and lets you define a placeholder image, error image, fade animation, and listener to have custom actions based on download result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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