Home java How to stretch a picture to the full available width

How to stretch a picture to the full available width

Author

Date

Category

There is a ImageView which is inside the LinearLayout . Because a picture can have both vertical and horizontal orientation, they also look differently, respectively, is it possible to somehow insert a picture (stretch it) to the entire available width, while fixing the height value. Those. so that in a rectangle with a fixed height and width equal to the size of the container in which the ImageView is located, it would be possible to set a picture (or its fragment) so that for any orientation of the picture they would look the same?

this is what I got


image_view.xml

& lt; ImageView
  android: id = "@ + id / imageView_message_image"
  android: layout_width = "match_parent"
  android: layout_height = "match_parent"
  android: clickable = "true"
  android: paddingTop = "5dp"
  android: src = "@ drawable / image"
  / & gt;

Answer 1, authority 100%

& lt; ImageView
  android: id = "@ + id / imageView_message_image"
  android: layout_width = "match_parent"
  android: layout_height = "match_parent"
  android: adjustViewBounds = "true"
  android: scaleType = "centerCrop"
  android: src = "@ drawable / image" / & gt;

The scaleType parameter is responsible for the size of the image itself, set using src (it won’t work for background !). The size of the ImageView itself is independent of the size of the original image.

scaleType = "centerCrop" means that the picture will be enlarged (keeping the aspect ratio) until at least one dimension is equal to the size of ImageView . Anything that will come out will not be visible (from the English crop – crop).

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions