iOS Question UI element position

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm testing (debug mode) a B4X code on B4A and B4i. Within B4A the panel (see code belove) has the correct height and all the panel ui views are diplayed correctly.
Running the same code with the same layout (copy and paste from B4A) within B4i I got a trucated panel height.

Within B4A panel height is 3300 and within B4i panel height is 662, therefore completely different values (see code and logs belove).
Why this ? Am i doing something wrong or is it the ios subsystem that has a different system for positioning ui objects ?

B4X:
Private Sub CreateItem () As B4XView
    
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.LoadLayout("CardFull_itemlayout")
    pnl.Height = btnNavigate.Top + 70dip
    
    Log ("btnNavigate.Top = " & btnNavigate.Top)
    Log ("pnl.Height = " & pnl.Height)
    '.....
   
End Sub

--> LOGS

B4A
----
btnNavigate.Top = 3108
pnl.Height = 3300

B4i
---
btnNavigate.Top = 592
pnl.Height = 662
 

luke2012

Well-Known Member
Licensed User
Longtime User
Is "CreateItem" executed after the PageResize?

After a check I found that "CreateItem" is called before B4XPage_Resize as you can see within the log...

B4i LOG
---------
Class (b4i_httpjob) instance released.
>>> CreateItem
Writing analzed variants.
btnNavigate.Top = 586
pnl.Height = 656
>>>B4XPage_Resize
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
1. You should only use %x / %y inside the Page_Resized event.

2. Values without scale are meaningless.

Hi Erel,
first of all thanks for your appreciated reply.
I always state that it is my first B4XPages project (and therefore I am not a B4XPages guru) but the point is that actually, within my B4XPages project, the page ui (and related layout script) is all handled within layout files (.bal and .bil) not within "Page_Resized" event.

From a layout perspective the shared B4X code that I wrote run as expected on B4A but not within B4i: B4A panel height is 3300 and within B4i panel height is 662.

B4X:
'PREVIOUS B4XPages page (call .LoadCard)
Sub clvCardList_ItemClick (Index As Int, Value As Object)
    Private ItemVal As CardValue = Value
    Private CardNID As Int = ItemVal.nid
   
    Wait For (AppGlobals.GetCardFullContent (CardNID, AppGlobals.user, AppGlobals.psw)) Complete (MissingCardContent As Map)
   
    B4XPages.ShowPage("card")
    CardPage.LoadCard (AppGlobals.CardFullContent)
End Sub

'CURRENT B4XPages page
Public Sub LoadCard (CardFullContent As Map)
    clvCardFull.Clear 'CustomListView

    'Create Card item and populate it with all the card fields
    Private CardFullVal As CardFullValue  
    CardFullVal.Address = CardFullContent.Get(AppGlobals.FIELD_CARD_ADDRESS)
    HtmlAddress = CardFullVal.Address
    CardFullVal.Title = CardFullContent.Get(AppGlobals.FIELD_CARD_TITLE)
    '.....
   
    Private pnl As B4XView = CreateItem (CardFullVal)
    clvCardFull.Add(pnl, CardFullVal)
    clvCardFull.sv.ScrollViewOffsetY = 0
End Sub

Private Sub CreateItem () As B4XView
   
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.LoadLayout("CardFull_itemlayout")
    pnl.Height = btnNavigate.Top + 70dip
   
    Log ("btnNavigate.Top = " & btnNavigate.Top)
    Log ("pnl.Height = " & pnl.Height)
    '.....
 
End Sub


Schermata 2021-10-26 alle 17.13.42.png
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
Root.width and Root.height instead of 100%x and 100%y.
Put a log(root.width) and a log(root.height) to see with sizes the page have.
Root.width and Root.height instead of 100%x and 100%y.
Put a log(root.width) and a log(root.height) to see with sizes the page have.

Hi Alexander,
i tried to make this change but the app crashed with this error :"Object was not initialized (UIImage)" and i don't know why.
I updated only the line from this: "pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)"
To this: "pnl.SetLayoutAnimated (0,0,0,Root.width, Root.height)"

MAIN ISSUE
The main concept is that the panel should be tall enough (long) to hold (display) all the ui elements that have been added (see designer image above).
This is OK within the B4A version of the B4XPages App but not within B4i versione of the B4XPages App.
 
Last edited:
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
The error has nothing to do with pnl.SetLayoutAnimated.

Hi Erel,
the compiler show the error within this line: "imgCard.SetBitmap(aImg.Resize(pnl.Width, 250dip, true))" (note that imgCard is defined within "CardFull_itemlayout" layout file).

B4X:
Private Sub CreateItem (cfv As CardFullValue) As B4XView
'code before...

    Private aImg As Bitmap = cfv.Img
    If aImg.IsInitialized Then
        imgCard.SetBitmap(aImg.Resize(pnl.Width, 250dip, true))
End Sub

I think I agree with you (that this error shouldn't be related to running ".SetLayoutAnimated ()" but the strange thing is that if I comment "pnl.SetLayoutAnimated (0,0,0,100% x, 100% y)" or
I change from this: "pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)" to this: "pnl.SetLayoutAnimated (0,0,0,Root.width, Root.height)" the above error is displayed.

If I enable "pnl.SetLayoutAnimated (0,0,0,100% x, 100% y)" just before "pnl.LoadLayout("CardFull_itemlayout")" the error disappears and the (B4i) app works correctly.

I did the above test also within the B4A version of the app (same identical code) and if I comment .SetLayoutAnimated () I got a crash and an error on the same B4X statement / line: "imgCard.SetBitmap(aImg.Resize(pnl.Width, 250dip, KeepAspectRatio))".

If I enable the "SetLayoutAnimated ()" the error disappear and the B4A App works correctly.

B4X:
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.LoadLayout("CardFull_itemlayout")

The error within B4A version is:

B4X:
java.lang.IllegalArgumentException: width and height must be > 0
    at android.graphics.Bitmap.createBitmap(Bitmap.java:1113)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:952)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:807)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize(CanvasWrapper.java:568)
    at cutethings.android.botegapp.businesscard._createitem(businesscard.java:394)
    at cutethings.android.botegapp.businesscard._loadcard(businesscard.java:815)
    at cutethings.android.botegapp.businesscardlist$ResumableSub_clvCardList_ItemClick.resume(businesscardlist.java:223)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1764)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8043)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)

But this is not my primary issue (I keep the "SetLayoutAnimated ()" and all work fine).
My main issue to solve is in #9 of this post (and I have this problem only within B4i versione of the app).

SOLVED:
B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
     LoadCard (AppGlobals.CardFullContent)
End Sub

I solved the panel resize problem calling the sub that buld and pupulate it with the B4XPage_Resize.
 
Last edited:
Upvote 0
Top