问题
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