Author Topic: Help with Centering Dynamically Added Children in Scroll View  (Read 4165 times)

Mogaba

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Hello,

Sorry if this was posted before, but I have been searching everywhere and trying a whole bunch of things and I still can't get this to work.
Basically, I have a scroll view and a grid and am adding elements dynamically to the grid at runtime. I got them to sort correctly, but now I can't get the grid to be
centered in the scroll view (or the elements to be centered in the scroll view).

I have tried the center on child/center on click method, which doesn't work...

Funny thing is that when I am running the game, if I change the scroll view's content origin from, say, center to top, the grid repositions perfectly! So I know there must be some way to do what I want, I am just missing it.

PLEASE HELP!! I really really need to get this fixed as soon as possible. Thank you so much for your time and assistance.

« Last Edit: July 31, 2014, 07:21:08 PM by Mogaba »

Mogaba

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Help with Centering Dynamically Added Children in Scroll View
« Reply #1 on: August 01, 2014, 12:34:10 PM »
Bump. Anyone? It is vital that I figure this out. Any help at all would be appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with Centering Dynamically Added Children in Scroll View
« Reply #2 on: August 01, 2014, 09:14:15 PM »
Pro tip: don't bump your own posts. I answer all posts in the order they were last answered/created, so from the oldest to newest. Bumping posts here achieves the opposite effect. ;)

Change the UIGrid's pivot point to Top. It's TopLeft by default. You can also call scroll view's ResetPosition() function after populating your content.

Mogaba

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Help with Centering Dynamically Added Children in Scroll View
« Reply #3 on: August 04, 2014, 12:52:17 PM »
Great thank you so much! Sorry for the self-bump, I was desperate :)

Would the best way to change the pivot be to add a UIWidget script to the grid?
I know how to change the pivot of the scroll view but not the grid itself.


Again, thank you!

EDIT: Never mind, found a solution here that worked out well. http://www.tasharen.com/forum/index.php?topic=6756.0
« Last Edit: August 04, 2014, 03:51:41 PM by Mogaba »