ImageView Gravity

agraham

Expert
Licensed User
Longtime User
The designer gravity should affect the drawn image. It works fine here
It doesn't work as expected on your FlickrViewer when I change the ImageView gravities in the Designer. I assume this is because you assign a new BitmapDrawable to the ImageView in the program. To get it to work I need to change the gravity of the assigned BitmapDrawables.

Do you know if there is a way, apart from redrawing it, to display a Bitmap in an ImageView scaled to fit but with the correct aspect ratio? The closest seems to be Gravity.FILL but that changes the aspect ratio to that of the ImageView so distorting the image.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It doesn't work as expected on your FlickrViewer when I change the ImageView gravities in the Designer. I assume this is because you assign a new BitmapDrawable to the ImageView in the program. To get it to work I need to change the gravity of the assigned BitmapDrawables.
That is correct. When you assign a new BitmapDrawable it gets erased.

Do you know if there is a way, apart from redrawing it, to display a Bitmap in an ImageView scaled to fit but with the correct aspect ratio? The closest seems to be Gravity.FILL but that changes the aspect ratio to that of the ImageView so distorting the image.
You can load the Bitmap with LoadBitmapScaled. It will make the bitmap smaller and will keep the correct aspect ratio.
You can also change the ImageView size based on the bitmap size.
 
Top