How to make glide display like picasso?

a 夏天 提交于 2019-12-05 22:02:14

By default, Glide will attempt to keep the aspect ratio of the images. When you use fitCenter(), this implies that you want the whole image visible and centered within the available area. Switching to centerCrop() would be the first step in making sure the image fills both the height and width available to it.

However, you are also running into a longstanding issue with GridView: it assumes all columns have the same height. Yet, you use wrap_content for your ImageView's height, causing each element to get resized differently based on the incoming height (remember, to Glide's perspective, you said your ImageView can be as tall as it needs to be!).

If you have a dominant aspect ratio (say, 16:9), you could use a fixed aspect ratio view such as this AspectRatioImageView which would always use the same height based on the width of the column (set by your GridView). Another, more complicated, option is to switch to RecyclerView and use a StaggeredGridLayoutManager, which would allow you to keep the aspect ratio of each image and stagger the rows, ensuring that each image fills the space and keeps its aspect ratio.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!