Author Topic: Making the contents of a ScrollView relative to screen size?  (Read 3121 times)

cnymose

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Making the contents of a ScrollView relative to screen size?
« on: March 12, 2014, 08:23:30 PM »
I tried adding anchors to the content of a ScrollView. While it gives me the correct size, I can't move it, since it's locked to the screen edges. So how exactly do we use anchors with contents of ScrollViews, or just make it relative to screen size?
Been searching and trying for hours now and this one just gets the best of me...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making the contents of a ScrollView relative to screen size?
« Reply #1 on: March 12, 2014, 09:31:03 PM »
You shouldn't anchor the contents of the scroll view. You can specify an Origin Point on the scroll view which will control where your content will begin. It will act as a soft anchor for your content.

cnymose

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Making the contents of a ScrollView relative to screen size?
« Reply #2 on: March 13, 2014, 07:03:01 AM »
Didn't solve it :/
Here is my screen:
http://i.imgur.com/vcDQoQZ.png
The top one is 1280x768
The bottom is 480x320

Now I've anchored the scrollview so it always has the same size relative to the screen, but then the content obviously doesn't follow, and get's clipped instead. Just need that last step now to make the content resized as well.

cnymose

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Making the contents of a ScrollView relative to screen size?
« Reply #3 on: March 13, 2014, 09:09:26 AM »
I've found a workaround:

For the shaded background you see, I simply script it to be:
GetComponent<UISprite>().SetDimensions((int)scrollView.GetComponent<UIPanel>().width,(int)GetComponent<UISprite>().height);

So that the backgrounds width and height is that of the scrollview's.
Then if i anchor all the buttons to the sides of the background, they will follow, and still be able to scroll through the ScrollView!
Then lastly, I will just have to figure out the aspect ratio between the buttons and the black background, and set the widths/heights accordingly.