glide如何设置图片大小

 时间:2026-02-13 01:59:14

1、理想情况下,你的服务器或者API能够返回给你恰好所需分辨率的图片,这是在网络带宽、内存消耗和图片质量下的完美方案。

2、跟Picasso比起来,Glide在内存上占用更优化。Glide在缓存和内存里自动限制图片的大小去适配ImageView的尺寸。Picasso也有同样的能力,但需要调用fit()方法。用Glide时,如果图片不需要自动适配ImageView,调用override(horizontalSize, verticalSize),它会在将图片显示在ImageView之前调整图片的大小。

3、Glide    .with(context)    .load(UsageExampleListViewAdapter.eatFoodyImages[0])    .override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio    .into(imageViewResize);

这个设置可能也是有利于没有明确目标,但已知尺寸的视图上。例如,如果app想要预先缓存在splash屏幕上,还没法测量出ImageVIews具体宽高。但,如果你已经知道图片应当为多大,使用override可以提供一个指定的大小的图片。

1、现在,对于任何图像的任何处理,调整图像的大小可能会扭曲长宽比,丑化图片的显示。在大多数情况下,你希望防止这种事情发升。Glide提供了变换去处理图片显示,通过设置centerCrop 和 fitCenter,可以得到两个不同的效果。

CenterCrop

CenterCrop()会缩放图片让图片充满整个ImageView的边框,然后裁掉超出的部分。ImageVIew会被完全填充满,但是图片可能不能完全显示出。

Glide    .with(context)    .load(UsageExampleListViewAdapter.eatFoodyImages[0])    .override(600, 200) // resizes the image to these dimensions (in pixel)    .centerCrop() // this cropping technique scales the image so that it fills the requested bounds and then crops the extra.    .into(imageViewResizeCenterCrop);

2、FitCenter

fitCenter()会缩放图片让两边都相等或小于ImageView的所需求的边框。图片会被完整显示,可能不能完全填充整个ImageView。

Glide    .with(context)    .load(UsageExampleListViewAdapter.eatFoodyImages[0])    .override(600, 200)    .fitCenter()    .into(imageViewResizeFitCenter);

  • 苹果手机如何关闭图标动态效果?
  • 苹果打字右下角麦克风去掉?
  • iOS手机/苹果手机怎么设置锁屏壁纸?
  • 苹果13下方小白条怎么隐藏
  • 苹果下面的横条怎么去掉
  • 热门搜索
    哈尔滨的旅游景点 中国旅游景点图片 广州到厦门旅游攻略 成都的旅游景点 阜阳市旅游局 湘西旅游景点大全 古北口镇旅游攻略 荞面旅游网 铜鼓旅游景点 鞍山旅游景点大全