I am using Glide to load URL into ImageView. My main problem is that when I scroll it seems like the sizing of the images are getting messed up which is causing some distortion. My relevant code is below.
XML (just the part relating to the ImageView):
<LinearLayout
android:id="@+id/image_holder_layout"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="center">
<ImageView
android:id="@+id/flyer_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:drawable/dialog_holo_light_frame" />
</LinearLayout>
RecyclerAdapter:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemHolder> {
private ArrayList<Item> items;
Context context;
public RecyclerAdapter(Context context, ArrayList<Item> items) {
this.items = items;
this.context = context;
}
@Override
public ItemHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
Context context = viewGroup.getContext();
boolean shouldAttachToParentImmediately = false;
View view = LayoutInflater.from(context).inflate(R.layout.list_row_flyer, viewGroup, shouldAttachToParentImmediately);
ItemHolder viewHolder = new ItemHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ItemHolder holder, int position) {
holder.bind(position);
}
@Override
public int getItemCount() {
return items.size();
}
class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView itemImage;
public ItemHolder(View view) {
super(view);
this.itemImage = (ImageView) view.findViewById(R.id.flyer_item_image);
}
void bind(int listIndex) {
Glide.with(context)
.load(items.get(listIndex).getImageUrl())
.placeholder(R.drawable.placeholder_flyer_item_image)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(itemImage);
}
}
}