iOS Question Label text: align vertically top

David Meier

Active Member
Licensed User
Longtime User
Hi
I have a label and want to align its text vertically atop. I read that iOS does not support this behaviour. Instead the solution could be sizetofit. But sizetofit will not work with my example. Can anybody help here?

Kind regards

David
 

Attachments

  • size2fit.zip
    2.2 KB · Views: 306

David Meier

Active Member
Licensed User
Longtime User
You must learn about the resize event and how it is handled in B4i: https://www.b4x.com/android/forum/t...mageview-in-customlistview.98235/#post-619467

This will work:
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
   Label1.SizeToFit
End Sub

Hi Erel
I tried it out and it works. But I use a XUI panel with a layout and here I struggle to use SizeToFit correctly. I want the to set the label text of a label that is positioned in a layout and assigned to a xui panel. I attached an example: Label1 without layout and panel work - lblLayout does not work.
Thanks for helping
David

---
major part of the code in the zip-file
B4X:
Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    Page1.RootPanel.LoadLayout("Page1")

    NavControl.ShowPage(Page1)
    
    addItem
End Sub

Sub addItem
    For i = 1 To 6
        Private pArticleOverview As B4XView = xui.CreatePanel("") ' declared public hence obsoliete declaration here
        pArticleOverview.SetLayoutAnimated(0,0,0,100%x,80)
        pArticleOverview.LoadLayout("clvLayout")
        clv1.Add(pArticleOverview, i)
    Next   
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    Label1.SizeToFit
    lblLayout.SizeToFit
    
End Sub
 

Attachments

  • size2fit.zip
    3.8 KB · Views: 281
Upvote 0

David Meier

Active Member
Licensed User
Longtime User
There is no such thing. A XUI panel is a regular panel.

Your code cannot work as you are only calling SizeToFit on the last added item.

Why aren't you using CLV.AddTextItem? It will resize the label for you.

Oh Erel, thx. I'd be so happy would I know only half as much as you ;)
I did not use clv.AddTextItem because in there are different items in a list cell. I have 3 labels and one image view. So I guess I need to use a panel. Or am I wrong here?
If you would explain, why only the last added item is affected by my SizeToFit call, I would also be grateful to you.

Kind regards

David
 
Upvote 0

David Meier

Active Member
Licensed User
Longtime User
I think I found a solution :). It is based on the video tutorial on customListviews. The base idea is to use a custom type. Whenever an item is added to the customListView, the custom type object gets a new item too. Later each of these custom type items can be referenced with sizeTofit in the resize sub. (in the panel layout I had to set handle resize event to false).
The relevant info start after minute 11 on the video.
I don't think this is a very elegant solution to vertically align a label text on a panel in a list :(. But it works, so I share this example here;).

Regards
David
 

Attachments

  • size2fit_v2.zip
    4 KB · Views: 314
Last edited:
Upvote 0
Top