I am looking for something like the CENTER_CROP in ImageView.ScaleType
Scale the image uniformly (maintain the image\'s aspect ratio) so that both dim
The simple and easy way if you are using ConstraintLayout.
XML
then
In Kotlin:
videoView.setOnPreparedListener { mediaPlayer ->
val videoRatio = mediaPlayer.videoWidth / mediaPlayer.videoHeight.toFloat()
val screenRatio = videoView.width / videoView.height.toFloat()
val scaleX = videoRatio / screenRatio
if (scaleX >= 1f) {
videoView.scaleX = scaleX
} else {
videoView.scaleY = 1f / scaleX
}
}
See my Java version answer here: https://stackoverflow.com/a/59069357/6255841
And this worked for me.