I'm just about to create my own custom ImageView, so I make the class below.
class MyImageView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
}
By default (i.e. without setScaleType(ScaleType.MATRIX)
), it looks below (fit well to the screen).
So if I add setScaleType(ScaleType.MATRIX)
in the init
it became as below.
class MyImageView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
init {
setScaleType(ScaleType.MATRIX)
}
}
Why was it shrink? What Can I do to still use ScaleType.MATRIX
yet have it initially display fitting the screen?
The Matrix scaletype is to apply no scale type to it by default, hence the image will get resized to its original size.
In this case, the image is smaller than the view, hence it is shrinked smaller. Without specifying the ScaleType, it will FitCenter, hence enlarge the smaller image to fit the view size.
More explanation here