Android Question How to get Layout Height?

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hello everyone!

Someone knows the right way to get the height of a layout?

I create a function to get the bottom of last view on layout, but not working because when I get the view.top and view.height, some views came wrong (with negative values).

B4X:
Sub FU_LayoutHeight(p As Panel) As Long
   
    Dim lMax As Long = 0
    For Each v As View In p.GetAllViewsRecursive
          Log(v.Tag & "/" & v.Top & "/" & v.Height)
          If v.Top + v.Height > lMax Then 
              lMax = v.Top + v.Height
          End If
    Next
    Return lMax
End Sub

Look the negative value of this Label (-30 ??????)

Image4.jpg


Image2.jpg


Somebody can explain that behavior?

Thank You

Alberto Iglesias
 

Attachments

  • laymosaico1.bal
    3.8 KB · Views: 248

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
OK I'm still using v6.0.0 of B4A.

I can't do something like this:
B4X:
    Dim q As Panel : q.Initialize("")
    q.Height = 1000
    q.LoadLayout("laymosaico1")

but you say to me in the version 7.3+ I can use some like this:
B4X:
    Dim q As Panel : q.Initialize("")
    q.SetLayout(......)   <- I dont know the parameters.....  Can I put Layout and Size, is correct?
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Thanks Manfred, you think this will work?

B4X:
Dim q AsPanel : q.Initialize("")
q.SetLayout (0,0,100%x, 1000)
q.LoadLayout("laymosaico1")
iHeight = Funcoes.FU_LayoutHeight(q)

with this can I get the correct size of layout? (in iHeight valriable)


Is the only way to get the size of layout??

I just need to know the sizes of each views in layout...... :-(
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
@DonManfred @Erel

I can't get the height of the layout after loading in a panel, like this:

B4X:
Dim q AsPanel : q.Initialize("")
q.SetLayout (0,0,100%x, 1000dp)
q.LoadLayout("laymosaico1")

I start a panel with 1000dp, but after loading some layout, I need to know where is the finish of the last object in this layout.

Do you have some idea for get the height of layout AFTER load the panel, independent of the size of panel

thanks
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hi Erel, my doubt is this:

I have a customlistview with different rows and each row I have a layout with different Height. like this little screenshot:
Image1.png


In this app I put something like this:

B4X:
        Case "layLayout1"
            iHeight = 105dip
             
        Case "layLayout2"
            iHeight = 280dip
                 
        Case "layLayout3"
            iHeight = 410dip

I understand this in unnecessary, is that right?

I can calculate the "height"of this layout to dimensioning the height of each row?

Whats the best practice to to that, without specifying size of each layout?


Thank you


Alberto Iglesias
 
Upvote 0
Top