Maintain aspect ratio to modify the background image android:scaletype= "Fitxy"

Source: Internet
Author: User

About the appearance of ImageView in Android, which is what the picture looks like, with Adjustviewbonds and ScaleType in the layout file
The relationship of the property. I have done some exploration. Now share with you, welcome to advise you. Set Adjustviewbonds to True and false, respectively, with a variety of scaletype, resulting in different effects. (The Adjstviewbonds value of the imagview above is false; the Adjstviewbonds value of the following imagview is true; two Imagview is the same size) as follows:

Code:

XML code
  1. <ImageView
  2. android:id="@+id/imageview1"
  3. android:layout_width="fill_parent"
  4. android:layout_height="200dip"
  5. android:adjustviewbounds="false"
  6. android:scaletype="centerinside"//each change here
  7. android:src="@drawable/ic_3" />//here two pictures are changed, one map is smaller in size and the other one is larger.
  8. <ImageView
  9. android:id="@+id/imageview2"
  10. android:layout_width="fill_parent"
  11. android:layout_height="200dip"
  12. android:adjustviewbounds="true"
  13. android:scaletype="centerinside"//each change here
  14. android:src="@drawable/ic_3" />//here two pictures are changed, one map is smaller in size and the other one is larger.

Original:





1, scaletype= "Matrix"
Pic1, Pic2.
is to keep the original size, starting at the point in the upper-left corner and drawing as a matrix.


Pic1

Pic2

2, scaletype= "Fitxy"
PIC3, Pic4.
is drawn after stretching the original image in a transverse direction (that is, the xy direction).


Pic3

Pic4

3, scaletype= "Fitstart"
PIC5, Pic6.
is the drawing of the original image in the upper-left corner (that is, the point at which the Matrix is drawn), scaled.


Pic5

Pic6

4, scaletype= "Fitcenter"
Pic7, Pic8.
Is the point at which the original image is centered along the top (that is, the center point of the first row of the Matrix Drawing), and the original drawing is scaled proportionally.


Pic7

Pic8

5, scaletype= "Fitend"
PIC9, PIC10. 、
Is the point at which the original image is centered along the bottom (that is, the center point of the last line of the matrix drawing), scaled by the original drawing.


Pic9

Pic10

6, scaletype= "Center"
Pic11, Pic12.
is to keep the original size, with the geometric center point of the original image and the geometric center point of the Imagview as the datum, only the Imagview size images are drawn.


Pic11

Pic12

7, scaletype= "Centercrop"
Pic13, Pic14.
does not maintain the original size, with the geometric center point of the original image and the geometric center point of the Imagview as the benchmark, only the Imagview-sized images are drawn (to fill
Imagview as the target, crop the original image).


Pic13

Pic14

8, scaletype= "Centerinside"
PIC15, PIC16.
does not maintain the original size, with the geometric center point of the original image and the geometric center point of the Imagview as the datum, only the Imagview size images are plotted (to display
The full picture is the target and the original image is scaled).


Pic15

Pic16

(It turns out that the adjustviewbonds is individually set without impact.) )

In my opinion, the types of scaletype are divided into three types of matrix (default), Fit-x class, and center class. The matrix doesn't say much. In the Fit-x class,
Between Fitstart, Fitcenter and Fitend, the original changes are adapted to the imgview as needed, and are drawn by the matrix, but they
The difference is that the benchmark is different. The Datum of the Fitstart is the point at the top corner (that is, the point at which the matrix starts) Fitcenter the Datum point as the midpoint
(The point at which the picture can be centered in matrix mode), while the Fitend datum point is the point at the lower-right corner (that is, the matrix is the last draw point). Center class
, center, Centercrop, and Centerinside are all based on the geometric center point of the original and the geometric center point of the Imagview, and only draw
Imagview size of the image, the difference is whether to maintain the original size of the drawing and the target of different, the means adopted.

Maintain aspect ratio to modify the background image android:scaletype= "Fitxy"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.