Android Question Problem setting the width of labels in a panel

Sanxion

Active Member
Licensed User
Longtime User
Guys

I am using the following code to set the sizes/positions of two types of panels that contain a header and a body label:

B4X:
For Each v As View In Activity
    If v Is Panel Then 

        Dim PanelTag As String
        PanelTag = v.Tag

        If PanelTag.StartsWith("Type1") Then
            If PanelTag.StartsWith("Type2") Then
                  v.Left = 10%x
                  v.Top = 10%y
                  v.Width = 80%x
              Else
                  v.Left = (Activity.Width - v.Width) / 2
                  v.Top = (Activity.Height - v.Height) / 2
              End If
        End If
    End If

    Next

I suspect the values for the panels are being set but the containing labels are not being adjusted accordingly. The actual "Type2" panel consists of 2 labels (header and body) - the anchors for the header are set to "Both" for the Horizontal Anchor and "Top" for the Vertical Anchor; the body anchors are "Both" for the HA and "Bottom" for the VA.

With these settings for the labels, should they not be sized and positioned according to the parent panel?

Thanks
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
The Anchors settings work only in the Designer; I mean, if you change the size of a panel by code, you must resize/reposition its internal labels by code.


(Note that your code:
B4X:
If PanelTag.StartsWith("Type1") Then
    If PanelTag.StartsWith("Type2") Then
is not logically correct).
 
Upvote 0
Top