Android Question Imageview Fit?

techknight

Well-Known Member
Licensed User
Longtime User
I know on iOS there is a FIT function for the imageview, which makes my logo look perfectly fine on the Drawer view.

But, on B4A, there is no FIT option so my logo doesnt look right. Even Fill, its off the screen.

any ideas?
 

techknight

Well-Known Member
Licensed User
Longtime User
Cant get it to work!

it keeps getting cut-off at the bottom. Tried it various ways including this one:

B4X:
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmapResize(File.DirAssets, "logo.png", imgLogo.Width, imgLogo.Height, True))
    bd.Gravity = Gravity.CENTER
  
    imgLogo.Background = bd

Shows great side-to-side. But top and bottom, Bottom gets cut off every time. hmmmm

Edit: On a different device, its a little teeny tiny logo in the top, even though gravity is center. ugh
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I think the height is being reported incorrectly.

I am attempting to put a logo into the ImageView that is in the B4XDrawer LEFT layout.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Because I dont know that exists. Nothing came up in search.

Edit: Nevermind, I saw that earlier. Trouble is, it looks like its all B4XView stuff for B4J? I am using a regular imageview. I dont see imageview b4Xview in the designer?

so how to adapt?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Ok, I tried it.

Still the same exact issue

B4X:
    Dim bmp2 As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "logo.png", imgLogo.Width, imgLogo.Height, True)
    FitImageToView(bmp2, imgLogo)

The imageview is the view inside Left.bal for the B4XDrawer example. I also tried without Resize, the result is identical.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
it can be used once after loadlayout
B4X:
Sub AdjustImageView(Imv As ImageView, bmp As Bitmap)

    'MR 09.09.2018 (from vb6)

    Dim bx1 As Long
    Dim by1 As Long
      
    Dim bx2 As Long
    Dim by2 As Long
      
    Dim f1 As Float
    Dim f2 As Float

    Dim ox,oy,oxx,oyy As Float

    ox = Imv.Left
    oy = Imv.Top
      
    oxx = Imv.Width
    oyy = Imv.Height
    
    bx1 = bmp.Width
    by1 = bmp.Height
      
    bx2 = oxx
    by2 = oyy

    If bx1 = 0 Or by1 = 0 Then 'größe wie PictureBox
        bx1 = bx2
        by1 = by2
    End If
      
    f1 = 1.0
    f2 = 1.0
    
    If bx1 <> bx2 Then 'ohne ZOOM > mit ZOOM <>
        f1 = bx2 / bx1
    End If
    If by1 <> by2 Then
        f2 = by2 / by1
    End If
    
    If f2 < f1 Then f1 = f2

    Imv.Gravity = Bit.Or( Gravity.FILL,Gravity.CENTER)
    
    Imv.Left = ox + oxx / 2.0 - (bx1 * f1) / 2.0
    Imv.Top = oy + oyy / 2.0 - (by1 * f1) / 2.0
    
    Imv.Width = f1 * bx1
    Imv.Height = f1 * by1
    
    Imv.Bitmap = bmp
    
End Sub
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I think I just found my problem. the controls are overlapping somehow in my layout, and I didnt even notice it because it was hidden behind another color. Whoops. This fixed it on my tablet.

However, there is still a bug on my phone, because the logo is really tiny squished at the top. But the image view looks fine itself.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I played around with the Anchors, removed the bottom anchor and that seems to have fixed it.

I guess I dont quite understand how Anchors are supposed to work, I guess.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…