I have a recycler view with different View Holders.
A couple of view holders have image views which I pass into Glide to display images.
The problem is, when
Add this line
android:adjustViewBounds="true"
to the imageview
in layout file it will automatically resize image view.
in glide change .crossFade()
to .fitCenter()
1 .
add android:adjustViewBounds="true"
to ImageView
<ImageView
android:id="@+id/img_item_my_show_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/backgrund_banner"/>
2.Change the following code to Glide
Glide.with(context).asBitmap().load(imgUrl)
.apply(RequestOptions()
.fitCenter()
.placeholder(R.drawable.default_img)
.error(R.drawable.error_img))
.into(ImageView)
I ran into the same issue and i solved it as below,
Glide.with(mContext)
.load(model.getImage())
.asBitmap()
.fitCenter()
.placeholder(R.drawable.ic_placeholder)
.error(R.drawable.ic_placeholder)
.into(holder.ivImage);
I just added .asBitmap() and .fitCenter() , Issue Resolved.
you must in onBindViewHolder set width of image
for example:
yourImageView.getLayoutParams().width = GetScreenWidthPx();
public int GetScreenWidthPx() {
DisplayMetrics displayMetrics = MyApp.GetContext().getResources().getDisplayMetrics();
return displayMetrics.widthPixels - DpToPx(your_margin_in_dp);
}
public static int DpToPx(int dp) {
DisplayMetrics displayMetrics =
MyApp.GetContext()
.getResources()
.getDisplayMetrics();
return (int) (dp * displayMetrics.density + 0.5f);
}
Try giving your recyclerview's item ImageView
an attribute as:
android:scaleType="fitXY"