Dynamic control width in a scrollable area

In a custom table cell I have a scrollable area.
I need to put X container controls within it, and I need to resize each to the width of the scrollable area.
I’ve tried setting a constraint dynamical but it crashes hard without raising an exception.

I’m missing something. I assumed that if I set each container’s width constraint to the width attribute of the scrollable area, this should work fine. Is the scrollable area not a “legal” parent of a container control that has been added to it?

It is usually a bad idea to have a vertical scrollable area within a table.
A table is already a subclass of scrollable area.

Anyway, it should still be possible.

Correct. The legal parent of any control in a MobileScrollabelArea is the MobileScrollableArea.Container which you must instantiate yourself.

  1. Make sure your scrollable area has a Container that is not nil.
MobileScrollableArea.Container = new MobileContainer //This should suffice
  1. Set the Container’s width to be equal to the scrollableArea’s width.

  2. You will then add X container controls as Childs of that container.

  3. Set each container’s width to be equal to MobileScrollableArea.Container’s width

I’ve been trying. It doesn’t want to work.
The .container reports back width and height of 0
When I dynamically add a control to it, it just never shows up.

ahhhh. I was setting the constraint on the control, not the container.
Starting to make progress now.

1 Like

Can you make a test project with just that part?

I will then be able to take a look at it

No need now. The trick was to add the constraint to the correct object and then to add a constraint for the width of the scroll areas container.

I meant to follow up with this.
It’s still not quite right.

I get the width of the scrollable area and set a new container to add the elements that will show up when scrolled. I’m setting Paging to true.

I then set the container’s width to the scrollable area’s width x the number of controls I’m embedding.
I loop through each control and set its with to the width of the scrollable area, and left edge to the correct constraint - either the container’s left edge or the right edge of the container that proceeded it.

There is some disconnect because as I swipe the next controls appear cut off or at least not correctly paging (see one sticking out).

Here’s the code. Any hints about what I might be doing wrong would be appreciated.

(Could it be not compensating for the scrollbar width or something?)

For i As Integer = 0 To cont.ControlCount-1
Var cv As MobileControl=cont.ControlAt(i)

Var WidthC As New iOSLayoutConstraint(cv,iOSLayoutConstraint.AttributeTypes.Width, iOSLayoutConstraint.RelationTypes.Equal, _
cont, iOSLayoutConstraint.AttributeTypes.Width,1/cont.ControlCount,0)

Var HeightC As New iOSLayoutConstraint(cv,iOSLayoutConstraint.AttributeTypes.Height, iOSLayoutConstraint.RelationTypes.Equal, _
Nil, iOSLayoutConstraint.AttributeTypes.None,1.0,h)

Var LeftC As iOSLayoutConstraint

If i=0 Then
leftc= New iOSLayoutConstraint(cv,iOSLayoutConstraint.AttributeTypes.Left, iOSLayoutConstraint.RelationTypes.Equal, _
cont, iOSLayoutConstraint.AttributeTypes.Left,1.0, 0 )
Else
leftc = New iOSLayoutConstraint(cv,iOSLayoutConstraint.AttributeTypes.Left, iOSLayoutConstraint.RelationTypes.Equal, _
cont.ControlAt(i-1), iOSLayoutConstraint.AttributeTypes.Right,1.0, 0 )
End If

cont.AddConstraint heightC
cont.AddConstraint widthC
cont.addconstraint leftC

Next