Loading images using Glide in Imageview

て烟熏妆下的殇ゞ 提交于 2019-12-13 15:25:52

问题


I am using Glide library for loading images in imageview and using the below code.

Glide.with(mActivity)
                .load(img.getmGridViewImageUrl())
                .placeholder(R.color.grey_light)
                .into(imageHolder.imageView);

The placeholder with grey color gets visible until the image does not load but after the image get loads in imageview, the placeholder still take place and show some blank space after that image.

How can I resolve this issue. Please help me if you have any idea here.


回答1:


Try this code.

When I give fix height to the ImageView it works for me.

Here's the layout

<ImageView 
    android:id="@+id/imgPoster"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/height_of_getInspired_list"
    android:layout_centerVertical="true"
    android:scaleType="fitXY" 
    android:src="@drawable/default_image"/>

Here's my code.

Glide.with(this.context).load(inspiredList.get(position).image)
.error(R.drawable.default_image)
.centerCrop()
.crossFade()
.placeholder(R.drawable.default_image).into(holder.imgPoster);



回答2:


Try this code.. This will help you..

Glide.with(this).load(photo_url)
            .crossFade()
            .thumbnail(0.5f)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.plaeholder_image)
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    imageView.setImageDrawable(resource);
                    return false;
                }
            })
            .into(imageView);

Please use placeholder image instead of color. you will able to use plain grey color image from drawable for placeholder image.



来源:https://stackoverflow.com/questions/35123738/loading-images-using-glide-in-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!