Android imageView image scaling method

  • 2020-12-09 01:02:17
  • OfStack

An example of imageView image scaling is presented in this paper. To share for your reference, the details are as follows:

android:scaleType can control the zoom mode of pictures. The sample code is as follows:


<ImageView android:id="@+id/img" 
  android:src=\'#\'" /logo"
  android:scaleType="centerInside"
  android:layout_width="60dip"
  android:layout_height="60dip"
  android:layout_centerVertical="true"/>

Note: centerInside represents scaling the image so that the length (width) of the image is less than or equal to the corresponding dimension of the view.

Note: The controlled image is resource, not background, android:src=\'#\'" /logo", not android:background=" @drawable /logo". I made this stupid mistake and the wrong person scaleType didn't work. The program dynamic loading image is similar, such as: should imgView. setImageResource(R. drawable.*); Rather than imgView. setBackgroundResource (R. drawable. *);

Additional details of scaleType description:

CENTER /center displays the image in the center of the view without scaling the image
CENTER_CROP/centerCrop scale the image so that the image length (width) is greater than or equal to the corresponding dimension of the view
CENTER_INSIDE/centerInside scale the image so that the image length (width) is less than or equal to the corresponding dimension of the view
FIT_CENTER/fitCenter scale the image to the smallest edge of the view and center it
FIT_END/fitEnd scales the image to the smallest edge of the view and displays it at the bottom of the view
FIT_START/fitStart scales an image to the smallest edge of the view to display at the top of the view
FIT_XY/fitXY displays images that are not scaled to the size of the view
MATRIX/matrix is drawn using matrices

I hope this article has been helpful in Android programming.


Related articles: