Alberto Iglesias Well-Known Member Licensed User Longtime User Sep 11, 2017 #1 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). Code: Copy 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 ??????) Somebody can explain that behavior? Thank You Alberto Iglesias Attachments laymosaico1.bal laymosaico1.bal 3.8 KB · Views: 328
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). Code: Copy 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 ??????) Somebody can explain that behavior? Thank You Alberto Iglesias
DonManfred Expert Licensed User Longtime User Sep 11, 2017 #2 Alberto Iglesias said: Somebody can explain that behavior? Click to expand... https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT Upvote 0
Alberto Iglesias said: Somebody can explain that behavior? Click to expand... https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT
Erel B4X founder Staff member Licensed User Longtime User Sep 12, 2017 #3 How do you load this layout? Upvote 0
Alberto Iglesias Well-Known Member Licensed User Longtime User Sep 12, 2017 #4 Code: Copy Dim q As Panel q.Initialize("") q.LoadLayout("laymosaico1") iHeight = Funcoes.FU_LayoutHeight(q) Wich the best way to get the bottom of last view of layout? Upvote 0
Code: Copy Dim q As Panel q.Initialize("") q.LoadLayout("laymosaico1") iHeight = Funcoes.FU_LayoutHeight(q) Wich the best way to get the bottom of last view of layout?
Erel B4X founder Staff member Licensed User Longtime User Sep 12, 2017 #5 This is a mistake. Check the logs you will see a warning. You must set the panel size before you load the layout. Is you are using B4A v7.3+ then you can set it with q.SetLayout. Upvote 0
This is a mistake. Check the logs you will see a warning. You must set the panel size before you load the layout. Is you are using B4A v7.3+ then you can set it with q.SetLayout.
Alberto Iglesias Well-Known Member Licensed User Longtime User Sep 12, 2017 #6 OK I'm still using v6.0.0 of B4A. I can't do something like this: Code: Copy 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: Code: Copy Dim q As Panel : q.Initialize("") q.SetLayout(......) <- I dont know the parameters..... Can I put Layout and Size, is correct? Upvote 0
OK I'm still using v6.0.0 of B4A. I can't do something like this: Code: Copy 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: Code: Copy Dim q As Panel : q.Initialize("") q.SetLayout(......) <- I dont know the parameters..... Can I put Layout and Size, is correct?
DonManfred Expert Licensed User Longtime User Sep 12, 2017 #7 https://www.b4x.com/android/help/views.html#panel_setlayout Upvote 0
Alberto Iglesias Well-Known Member Licensed User Longtime User Sep 12, 2017 #8 Thanks Manfred, you think this will work? Code: Copy 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
Thanks Manfred, you think this will work? Code: Copy 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...... :-(
DonManfred Expert Licensed User Longtime User Sep 12, 2017 #9 Based on the Valuees you use. You already know the real height. Note that you should use 1000dp instead of 1000 Though Code: Copy Funcoes.FU_LayoutHeight(q) will still return -1 or -2 (because you are using anchors) i guess. Upvote 0
Based on the Valuees you use. You already know the real height. Note that you should use 1000dp instead of 1000 Though Code: Copy Funcoes.FU_LayoutHeight(q) will still return -1 or -2 (because you are using anchors) i guess.
Erel B4X founder Staff member Licensed User Longtime User Sep 13, 2017 #10 The way to set the panel size in older versions of B4A is to add it to an Activity or any other panel: Code: Copy Activity.AddView(q, 0, 0, width, height) q.LoadLayout(...) q.RemoveView 'remove the panel from the activity Upvote 0
The way to set the panel size in older versions of B4A is to add it to an Activity or any other panel: Code: Copy Activity.AddView(q, 0, 0, width, height) q.LoadLayout(...) q.RemoveView 'remove the panel from the activity
Alberto Iglesias Well-Known Member Licensed User Longtime User Sep 13, 2017 #11 OK. thank you very much Erel Upvote 0
Alberto Iglesias Well-Known Member Licensed User Longtime User Mar 19, 2018 #12 @DonManfred @Erel I can't get the height of the layout after loading in a panel, like this: Code: Copy 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
@DonManfred @Erel I can't get the height of the layout after loading in a panel, like this: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Mar 20, 2018 #13 I'm not sure what you mean with "the height of layout". The panel size will never change when you call Panel.LoadLayout. Upvote 0
I'm not sure what you mean with "the height of layout". The panel size will never change when you call Panel.LoadLayout.
Alberto Iglesias Well-Known Member Licensed User Longtime User Mar 20, 2018 #14 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: In this app I put something like this: Code: Copy 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
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: In this app I put something like this: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Mar 20, 2018 #15 It is always the container that sets the layout size. You do need something like you did. Upvote 0
Alberto Iglesias Well-Known Member Licensed User Longtime User Mar 20, 2018 #16 But I can change the height of this container after load the layout or not? based on bottom of last component of this layout? Upvote 0
But I can change the height of this container after load the layout or not? based on bottom of last component of this layout?
Erel B4X founder Staff member Licensed User Longtime User Mar 20, 2018 #17 Alberto Iglesias said: But I can change the height of this container after load the layout or not? Click to expand... You can change it however it will not affect the views previously added. Upvote 0
Alberto Iglesias said: But I can change the height of this container after load the layout or not? Click to expand... You can change it however it will not affect the views previously added.
Alberto Iglesias Well-Known Member Licensed User Longtime User Mar 20, 2018 #18 OK. so, my solution is the correct one! Thank you! Upvote 0