Bug? [SOLVED] Horizontal Anchor unexpected result with ScrollView

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have a layout with a bunch of Labels on it. They are effectively arranged in 2 columns with a description on the left & a value on the right. I initially had them laid out directly on the Activity with the left column using a left horizontal anchor & the right column using a right horizontal anchor (with a right edge distance of 55). This has worked well for me in various apps over a long period of time.

After I added a few extra Labels, I found that the layout was too big for the Activity, so I created a panel & cut & pasted the labels from the activity to the panel. Then I changed my activity code so that the panel is loaded onto a ScrollView.

All this works well except I can't see the values in the right hand labels. When I step through my code, I find that after the layout has been loaded into the ScrollView, the left position of the right hand labels is a large negative number (eg: -300) - so they are positioned well off the left side of the Activity. The only way I have been able to get it to work properly is to set the horizontal anchor of the right views to left.

Is this a bug, or am I missing something?

- Colin.

rightanchor.png


nolabels.png



leftanchor.png


labels.png
 

JordiCP

Expert
Licensed User
Longtime User
Seems as if the the label's positions have been evaluated when the panel's dimensions were 0, so any anchor to the left is ok, but not those from the right --> the -300 make sense as the sum of the right anchor distance plus the label width if the panel's width is 0
Are you loading the layout inside the scrollview inner panel before having sized it? Time ago I found a similar issue and if I remember correctly, was related to it.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Seems as if the the label's positions have been evaluated when the panel's dimensions were 0, so any anchor to the left is ok, but not those from the right --> the -300 make sense as the sum of the right anchor distance plus the label width if the panel's width is 0
Are you loading the layout inside the scrollview inner panel before having sized it? Time ago I found a similar issue and if I remember correctly, was related to it.
Yeah thanks @JordiCP - you're right. That's exactly what was happening. If I set the scrollview panel width to 100%x before I load the layout into it, it works fine with the horizontal anchor set to right.

Just one of those little traps for the unwary...!

- Colin.
 
Top