开发者

How to insert a progress bar on a image view programatically

I have defined a image view programatically and updating it asynchronously with the images down开发者_如何学Cloaded from the webservice.

Now, i want to add a progress bar to image view so that the image view will show the progress bar till the image is loaded. I have not defined the imageview in the xml file because i am updating it inside a horizontal scroll view.

Please help need it desperately...!!!

Here's the code that i am updating the image view

protected ImageView asImageView(final String message,final String path){
    final ImageView iv=new ImageView(this);


    AsyncImageLoaderv asyncImageLoaderTop = new AsyncImageLoaderv();
    Bitmap cachedImageTop=
    asyncImageLoaderTop.loadDrawable(
            path, new AsyncImageLoaderv.ImageCallback() {
                public void imageLoaded(Bitmap imageDrawable,
                        String imageUrl) {

                    iv.setImageBitmap(imageDrawable);
                }
            });
    iv.setImageBitmap(cachedImageTop);
    iv.setScaleType(ImageView.ScaleType.FIT_XY);
    LinearLayout.LayoutParams params=  new LinearLayout.LayoutParams(100,120);
    params.setMargins(10, 10, 10, 10);
    iv.setLayoutParams(params);

    iv.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            startActivity(new Intent(getApplicationContext(),
                    ShowPhotoActivity.class).putExtra("imagePath",
                    path).putExtra("message", message));


        }
    });
    return iv;
}


I know this is a few years old, but I figured I'd still post as it might help someone in the future...

You should use the library provided by Koush. It is extremely simply and straightforward to use. Plus it handles all the complicated stuff for you automatically!

https://github.com/koush/UrlImageViewHelper

Documentation and further explanation is available at the URL above - no need to reproduce here.


I've just had a similar problem. I'm not sure you can insert a ProgressBar on an ImageView, but you can display it in place of the imageview, and then hide it using setVisibility(View.GONE). I see your function returns ImageView. Perhaps it could return View type, and then if no image is present, it could return a ProgressBar which is also a View? Alternatively, you could create and use an AnimationDrawable of yours.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜