0
votes

This is a bit hard to explain, so I'll try with an example.

Let's say I've got a 3:2 image, that it'd like in one of my applications. I'd like the width of the ImageView to match its parent (match_parent), and I'd like the height to scale according to the aspect ratio of the image and the width of the image.

How is that possible in Android? I'd really like to know if there's a better way than creating pre-defined sizes for all kinds of different screen resizes.

Another scenario could be a grid view with lots of items - it'd be great if I could just tell Android how many items it should show in each row and what aspect ratio these items should have. It'd make things so much easier.

2

2 Answers

0
votes

What about the scaling parameters for the ImageView? Probably something like this:

<ImageView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:scaleType="whatever you want"
/>
0
votes

Best solution is to simply set a layout_width and layout_height and then set the android:scaleType to centerCrop. It's far from perfect, but works OK, and you can get some fairly decent results if you use auto_fit with a GridView.