简体   繁体   中英

GridView Image Width and Height

I have a GridView with ImageView s in it. Current, the images (which are all portrait orientation) are scaled down so that they fit the height of the rows, even though this leaves a large amount of empty space around the sides of the image. I've attempted adjusting the ImageView ScaleType :

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

CENTER_CROP and FIT_XY both provide seamless edge-to-edge images, however they either stretch/compress or crop the image to the size of the containing cell in the grid. How can I scale the cell larger to accommodate the height of the image when the width fills the column?

The property I was missing here was adjustViewBounds . Setting this to true makes the ImageView scale to fit the image it contains.

Done in XML:

<ImageView adjustViewBounds="true">

Done in Java:

imageView.setAdjustViewBounds(true):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM