How to programmatically insert a progress bar on an image

I defined the image representation programmatically and updated it asynchronously with the images downloaded from the web service.

Now I want to add a progress bar to the image view so that the image displays a progress bar before loading the image. I did not define the image in the xml file because I am updating it in horizontal scrolling.

Please help him in despair ... !!!

Here is the code that I update 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;
}
+3
source share
2 answers

I know that this is already several years, but I thought that I would publish it anyway, as this may help someone in the future ...

, Koush. . , !

https://github.com/koush/UrlImageViewHelper

URL- - .

+3

. , ProgressBar ImageView, , setVisibility (View.GONE). , ImageView. , View, , , ProgressBar, View? AnimationDrawable.

+1

Source: https://habr.com/ru/post/1779555/


All Articles