Mayur R. Amipara
Mayur R. Amipara

Reputation: 1224

what is the meaning of ImageView.ScaleType="MATRIX" : Android

I know about the matrix, its structure and working about image view's scale-type. but,

  1. I can't find the exact meaning of ImageView.ScaleType="MATRIX". By declaring this, what exactly happens while drawing the image view.

  2. When can I use ImageView.ScaleType="MATRIX" ?

  3. How does it differ from FIT_END & FIT_START

I googled about it and also referred the official link but was not able to find the exact answer.

Upvotes: 19

Views: 24383

Answers (4)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75798

ScaleType="MATRIX"

A Matrix is constructed and scaled based on the user’s pinch gesture scale factor and then the ImageView set based on this scaled Matrix. Please visit here Android ImageView ScaleType

Check the Effect.And https://guides.codepath.com/android/Working-with-the-ImageView

Upvotes: 2

Bryan Herbst
Bryan Herbst

Reputation: 67259

The documentation you linked to provides the answer you are looking for.

Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix). From XML, use this syntax: android:scaleType="matrix"

Although you mentioned that you already know what a Matrix is in the context of graphics, I will explain briefly for the sake of other users who come across this question- A matrix can be used to manipulate the canvas when drawing graphics. In the case of an ImageView's matrix, you can use it to translate, flip, rotate, or otherwise move the image around on the screen.

when i can use ImageView.ScaleType="MATRIX"

You can use it whenever you want with an ImageView. You can call setScaleType() in your Java code to use a matrix scale type or you can add the android:scaleType="matrix" attribute in your layout XML.

how it differs from FIT_END & FIT_START

FIT_END and FIT_START both actually use a Matrix to scale your image. Both maintain the original aspect ratio and fit the image entirely within the view, but just align the result differently. End will align the scaled image to the end of the ImageView, whereas start will align the scaled image to the start of the ImageView

Upvotes: 3

bitsoverflow
bitsoverflow

Reputation: 606

  1. ImageView.ScaleType.MATRIX lets you use a Matrix to scale the image. You can set the Matrix using ImageView.setImageMatrix(matrix). So by declaring the scaleType to MATRIX you are saying that you want to use an explicit Matrix to do that.
  2. You can use imageView.setScaleType(ImageView.ScaleType.MATRIX) whenever you want to customize the way the your image scales, rotates, etc. at your desire.
  3. FIT_END and FIT_START are default types of scale. So, if you use FIT_END for instance, your image will maintain the original aspect ratio and it will align the result of the right and bottom edges of your image view. So basically, the difference is that FIT_END and FIT_START are "presets" while with MATRIX you declare that you want to use your own matrix to scale.

Read the docs for more info

Upvotes: 15

Durgesh Patel
Durgesh Patel

Reputation: 1105

As per my understanding, Use below details for each ImageView's ScaleType attributes

center

Displays the image centered in the view with no scaling.

centerCrop

Scales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view.

centerInside

Scales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center.

fitCenter

Scales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view.

fitStart

Same as fitCenter but aligned to the top left of the view.

fitEnd

Same as fitCenter but aligned to the bottom right of the view.

fitXY

Scales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio.

matrix

Scales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

Upvotes: 4

Related Questions