Image resolution unclear

ukimiku

Active Member
Licensed User
Longtime User
With the designer, I create an ImageView, 45 x 45. Since the scale of my device is 2.0, I can load bitmaps of 90x90 pixels into this ImageView, and they look very crisp.

Now when I programmatically add an ImageView to the Activity, size 45dip x 45dip, the same 90x90 pixel bitmap does not fit anymore. Instead, the ImageView centers on a portion of the bitmap and crops it.

I can, however, load bitmaps of size 45x45 pixels into this ImageView, but then they are enlarged by a factor of 2, making them a little fuzzy around the edges.

I don't understand the logic behind this centering/enlarging. Could somebody please explain?

Thank you.

Regards,
 

ukimiku

Active Member
Licensed User
Longtime User
Yep, please find the demo project attached.

B4X:
Sub Globals
       Dim DesignerImageView As ImageView                           ' has been created with the designer
   DesignerImageView.Initialize("DesignerImageView")
   
   ' And now an imageview created in code
   Dim CodeImageView As ImageView
   CodeImageView.Initialize("CodeImageView")   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("layout")
   Activity.AddView(CodeImageView, 10dip, 10dip, 45dip, 45dip)
   CodeImageView.Bitmap = LoadBitmap(File.DirAssets, "add.png")
   
   DesignerImageView.Bitmap = LoadBitmap(File.DirAssets, "add.png")
End Sub

In the "Files" section, there is only "add.png" (90x90 png) and "layout.bal", on which I created a 45x45 ImageView with the Designer, named DesignerImageView. Since the scale of my phone is 2.0, the DesignerImageView displays the 90x90 picture perfectly, but the ImageView generated in code, named CodeImageView, does not.

Regards,
 

Attachments

  • ImageViewConfusion.zip
    11.6 KB · Views: 183
Last edited:
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
Yes, this works indeed. "Gravity" is a strange term for this behavior.
Thank you.

Regards,
 
Upvote 0
Top