Created
December 11, 2020 10:18
-
-
Save dadouf/f2ad0d625a70dff82f8c3295008c3641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onBindViewHolder(vh: VH, position: Int) { | |
val image = images[position] | |
// Resize view to respect aspect ratio | |
val imageAspectRatio = image.aspectRatio | |
val targetImageWidth: Int = | |
if (imageAspectRatio < maxImageAspectRatio) { | |
// Tall image: height = max, width adjusts | |
(maxImageHeight * imageAspectRatio).roundToInt() | |
} else { | |
// Wide image: width = max | |
maxImageWidth | |
} | |
vh.imageView.layoutParams = RecyclerView.LayoutParams( | |
targetImageWidth, | |
RecyclerView.LayoutParams.MATCH_PARENT | |
) | |
// Load image | |
Glide.with(vh.imageView).load(image.url).into(vh.imageView) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment