erfan erfan - 5 months ago 89
Java Question

Loading image with glide is slow

I have app connect with server and when pics load seems so slow and when scroll that up and down seems glide want read image again!
This is my adapter of glide:


public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private Context context;
private ArrayList<AndroidVersion> android;

public DataAdapter(Context context,ArrayList<AndroidVersion> android) {
this.context = context; = android;

public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_row, viewGroup, false);
return new ViewHolder(view);

public void onBindViewHolder(DataAdapter.ViewHolder viewHolder, int i) {


// load image into imageview using glide

public int getItemCount() {
return android.size();

public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv_name,tv_version,tv_api_level;
public ImageView tv_image;
public ViewHolder(View view) {

tv_name = (TextView)view.findViewById(;
tv_version = (TextView)view.findViewById(;
tv_api_level = (TextView)view.findViewById(;
tv_image= (ImageView) view.findViewById(;



If any one can help please do that!


Just add this when you get image from URL, this code reduces the size of that image

you can also do this,

ByteArrayOutputStream bytes = new ByteArrayOutputStream();

    //save scaled down image to cache dir
    newBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

    File imageFile = new File(filePath);

    // write the bytes in file
    FileOutputStream fo = new FileOutputStream(imageFile);

check this example