开发者

Display ProgressBar while image is loading in ImageView?

开发者 https://www.devze.com 2023-02-15 18:04 出处:网络
Is there a way to \"swap\" out a view at runtime? Here\'s my goal: I want to display an animated, indeterminate ProgressBar view until my image is loaded. Is there a way to do this easily, without hav

Is there a way to "swap" out a view at runtime? Here's my goal: I want to display an animated, indeterminate ProgressBar view until my image is loaded. Is there a way to do this easily, without having 开发者_StackOverflow社区to do a bunch of crazy stuff? Is there a way I can get the resource ID of the ProgressBar spinner animation and simply reuse that?


Yes. I tend to make a FrameLayout which contains both an ImageView and a ProgressBar. In onCreate() I do imageView.setVisibility(View.INVISIBLE) and then once the image loads I do:

progress.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.VISIBLE);

In terms of the threading you should as always use AsyncTask. This is easily the most complicated part of the process, although still quite manageable. Check out this answer for a full code listing.

0

精彩评论

暂无评论...
验证码 换一张
取 消