Using of ConstraintLayout to set your ImageView in 16:9 ratio


This article shows how to set the Bitmap into ImageView to keep ratio 16:9.

Since PercentFrameLayout and PercentRelativeLayout were deprecated in API level 26.0.0, I’d suggest you to consider using of ConstraintLayout to keep ratio 16:9 for your ImageView.

ConstraintLayout is really powerful tool to build Responsive UI for Android platform, you can find more details here Build a Responsive UI with ConstraintLayout.

Here is the example how to build your ImageView into ConstraintLayout to keep 16:9 ratio:

Or instead of editing your XML file, edit your layout directly in Layout Editor: