Android Glide placeholder size

后端 未结 4 659
醉话见心
醉话见心 2021-01-07 23:25

I have a problem with Android Glide. I am trying to quickly swap my image, they just become all placeholder size, and my placeholder image is very low size. So what I need t

4条回答
  •  自闭症患者
    2021-01-07 23:59

    What I did in this regard was to use override() to enforce image size. If you have a gridview and you need to have two images in each row, this is how you find the screen size in pixels to calculate the correct width and height of the image:

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        placeholderWidth = size.x / 2 ;
        placeholderHeight = size.x * 3 / 2 ; // based on the image's height to width ratio
    

    Once the desired width and height for each image is in hand, it's easy to use override:

        Glide.with(context)
                .load(url)
                .placeholder(R.drawable.loading)
                .override(placeholderWidth,placeholderHeight)                
                .into(viewHolder.imageViewHolder);
    

提交回复
热议问题