ScaleType is used for uniformly scaling the image bounds to the ImageView. Android ImageView provides various types of ScaleType for different configurations.
- CENTERĀ
- CENTER_CROP
- CENTER_INSIDE
- FIT_CENTER
- FIT_END
- FIT_START
- FIT_XY
- MATRIX
Now, we will look at each of these ScaleType in detail. For exploring these scale types we will use the Lazyroar logo as our image resource also set the background color of ImageView as black for the reference purpose.
1. CENTER
This scale type will center the image inside the view. But, it does not perform any scale to the image. Below is the code for the CENTER scale type.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "center" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
2. CENTER_CROP
This scale type scale the image uniformly .i.e., maintain the imageās aspect ratio in order to make the dimensions(width and height) equal to or larger than the Ā ImageView dimension.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "centerCrop" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
3. CENTER_INSIDE
CENTER_INSIDE will center the image inside the ImageView container. This scale type does not match the image edge to the edge of the view.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "centerInside" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
4. FIT_CENTER
It will scale the image from the center. FIT_CENTER makes sure that the image is completely fit inside the ImageView and the imageās vertical or the horizontal axis is going to be exactly the same as the view.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "fitCenter" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
5. FIT_END
It is used to scale the image file to the end of the view(ImageView). This scale type scale the image from the end of the container.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "fitEnd" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
6. FIT_START
This is used to scale the image to the start of the container. FIT_START scale the image from the start of the container.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "fitStart" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
7. Ā FIT_XY
FIT_XY done the scaling using the fill attribute. It will fill the image from the X and Y coordinates of ImageView.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "fitXY" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
8. MATRIX
It is used to scale the image using the image matrix when drawing. It is recommended to use whenever you want to customize the way you want to rotate the image or scale the image etc.
XML
< ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/simpleImageView" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:scaleType = "matrix" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> |
Example
In this example, we will perform scaling using the various scale type attributes on the click event listener of a button and shows the image with various scale type, and also toast a message for the name of the scale type.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Adding resources
Before moving further, we will add the following color attributes in our colors.xml resource file. Go to res > values > colors.xml and add them.
XML
< resources > Ā Ā Ā Ā < color name = "colorPrimary" >#0F9D58</ color > Ā Ā Ā Ā < color name = "colorPrimaryDark" >#16E37F</ color > Ā Ā Ā Ā < color name = "colorAccent" >#03DAC5</ color > </ resources > |
Step 3: Creating the layout file
In this step, we will create the layout for our application. For this, we are using the buttons for various scale types. Below is the code for the activity_main.xml file.
XML
<? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout Ā Ā Ā Ā android:layout_width = "match_parent" Ā Ā Ā Ā android:layout_height = "match_parent" Ā Ā Ā Ā android:orientation = "vertical" Ā Ā Ā Ā tools:context = ".MainActivity" > Ā Ā Ā Ā Ā Ā < ImageView Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_image" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "fill_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "200dp" Ā Ā Ā Ā Ā Ā Ā Ā android:src = "@drawable/gfg" Ā Ā Ā Ā Ā Ā Ā Ā android:background = "@color/black" Ā Ā Ā Ā Ā Ā Ā Ā tools:ignore = "MissingConstraints" /> Ā Ā Ā Ā Ā Ā < LinearLayout Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "match_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā android:orientation = "horizontal" > Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_center" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "CENTER" /> Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_center_crop" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "CENTER_CROP" /> Ā Ā Ā Ā Ā Ā </ LinearLayout > Ā Ā Ā Ā Ā Ā Ā Ā < LinearLayout Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "match_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā android:orientation = "horizontal" > Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_center_inside" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "CENTER_INSIDE" /> Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_fit_center" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "FIT_CENTER" /> Ā Ā Ā Ā Ā Ā </ LinearLayout > Ā Ā Ā Ā Ā Ā < LinearLayout Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "match_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā android:orientation = "horizontal" > Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_fit_end" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "FIT_END" /> Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_fit_start" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "FIT_START" /> Ā Ā Ā Ā Ā Ā </ LinearLayout > Ā Ā Ā Ā Ā Ā < LinearLayout Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "match_parent" Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā android:orientation = "horizontal" > Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_fit_xy" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "FIT_XY" /> Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā < Button Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:id = "@+id/st_matrix" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_width = "0dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_height = "wrap_content" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_margin = "8dp" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:layout_weight = "1" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:backgroundTint = "@color/colorPrimary" Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā android:text = "MATRIX" /> Ā Ā Ā Ā Ā Ā </ LinearLayout > Ā Ā </ LinearLayout > |
Step 4: Working with MainActivity.java file
In this step, we will initialize our ImageView and Buttons and attach a listener to them. On completion of the listener event, a toast message will be shown about the name of the scale type. Ā We can also setup the scale type using java code. Below is the code for the MainActivity.java file.
Java
import androidx.appcompat.app.AppCompatActivity; Ā Ā import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; Ā Ā public class MainActivity extends AppCompatActivity implements View.OnClickListener { Ā Ā Ā Ā Ā Ā private ImageView img; Ā Ā Ā Ā private Button center, center_crop, center_inside, fit_center, fit_end, fit_start, fit_xy, matrix; Ā Ā Ā Ā Ā Ā @Override Ā Ā Ā Ā protected void onCreate(Bundle savedInstanceState) { Ā Ā Ā Ā Ā Ā Ā Ā super .onCreate(savedInstanceState); Ā Ā Ā Ā Ā Ā Ā Ā setContentView(R.layout.activity_main); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā // Initializing method.. Ā Ā Ā Ā Ā Ā Ā Ā init(); Ā Ā Ā Ā } Ā Ā Ā Ā Ā Ā private void init(){ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img = findViewById(R.id.st_image); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā center = findViewById(R.id.st_center); Ā Ā Ā Ā Ā Ā Ā Ā center.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā center_crop = findViewById(R.id.st_center_crop); Ā Ā Ā Ā Ā Ā Ā Ā center_crop.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā center_inside = findViewById(R.id.st_center_inside); Ā Ā Ā Ā Ā Ā Ā Ā center_inside.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fit_center = findViewById(R.id.st_fit_center); Ā Ā Ā Ā Ā Ā Ā Ā fit_center.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fit_end = findViewById(R.id.st_fit_end); Ā Ā Ā Ā Ā Ā Ā Ā fit_end.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fit_start = findViewById(R.id.st_fit_start); Ā Ā Ā Ā Ā Ā Ā Ā fit_start.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fit_xy = findViewById(R.id.st_fit_xy); Ā Ā Ā Ā Ā Ā Ā Ā fit_xy.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā matrix = findViewById(R.id.st_matrix); Ā Ā Ā Ā Ā Ā Ā Ā matrix.setOnClickListener((View.OnClickListener) this ); Ā Ā Ā Ā } Ā Ā Ā Ā Ā Ā public void onClick(View view){ Ā Ā Ā Ā Ā Ā Ā Ā switch (view.getId()){ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_center: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.CENTER); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - CENTER" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_center_crop: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.CENTER_CROP); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - CENTER_CROP" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_center_inside: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - CENTER_INSIDE" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_fit_center: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.FIT_CENTER); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - FIT_CENTER" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_fit_end: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.FIT_END); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - FIT_END" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_fit_start: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.FIT_START); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - FIT_START" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_fit_xy: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.FIT_XY); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - FIT_XY" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā case R.id.st_matrix: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā img.setScaleType(ImageView.ScaleType.MATRIX); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Toast.makeText( this , "SCALE TYPE - MATRIX" , Toast.LENGTH_SHORT).show(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā break ; Ā Ā Ā Ā Ā Ā Ā Ā } Ā Ā Ā Ā } Ā Ā } |
Output: