Author Topic: Scrollable List populated at run-time has incorrect start position  (Read 3564 times)

Teric

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
I have set up a scrollable list using a UIScrollView component.  The child of the scroll view is a UITable, which in turn has a number of instantiated prefabs added to it at run-time.  All seems to work well, except for the fact that when the scroll view is first created and populated during run-time, the list of objects appears to be positioned a bit downward from where it should be (see attached picture).

As soon as I click and drag the list, it automatically resets itself to the correct position, and then allows me to drag it normally.  I have attempted the following things to fix this issue, but none of them have fixed the problem:

1.  Setting anchors to 'none' in the UIPanel component on the scroll view object
2.  Setting the content origin to 'top' in the UIScrollView component
3.  Adding/Removing a SpringPanel component
4.  In code, calling ResetPosition() on the UIScrollView object, and then destroying and detaching all children of the UITable object before populating it with new prefabs

We're scratching our heads over here--anyone seen a problem like this before?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable List populated at run-time has incorrect start position
« Reply #1 on: April 18, 2014, 05:10:30 PM »
Either move up the table's game object by however many pixels it's short by, or call UIScrollView's UpdatePosition() after setting up your content.

Teric

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Scrollable List populated at run-time has incorrect start position
« Reply #2 on: April 21, 2014, 10:48:57 AM »
Thank you very much, Aren!  It looks like that did exactly what we needed.

vivek_srinivasan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Scrollable List populated at run-time has incorrect start position
« Reply #3 on: May 26, 2014, 06:48:27 AM »
@Aren: I have got similar issue with ngui's scrollview. I am creating a table as a child of scrollview and for the first time alone ,the table including the cells gets offseted from the starting position of the scrollview. However from the next time it automatically gets shifted to the start. I want to know how you solved it. Thanks! 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable List populated at run-time has incorrect start position
« Reply #4 on: May 26, 2014, 11:03:06 PM »
Exactly as I mentioned in the previous post. Call UpdatePosition(), or if you're doing it at edit time -- right click on the scroll view and choose Reset Clipping Position. Might want to set the scroll view's origin too though.