Search Unity

ScrollView is not adjusting size of ViewPort/Content

Discussion in 'UGUI & TextMesh Pro' started by mrpmorris, Jan 27, 2018.

  1. mrpmorris

    mrpmorris

    Joined:
    Dec 25, 2012
    Posts:
    50
    1. Add a ScrollView to a canvas
    2. Resize the height so that you can see all of the client area
    3. Add a button inside the Viewport/Content element
    4. Add another button under it, and scroll it down so that it disappears just off the bottom, out of sight
    5. Run the app
    Expected: I should be able to scroll the scroll view to see the lower button

    Actual: I am able to pull the view so that the lower button is visible, but when I release the mouse button it snaps back so the button is not visible

    Even if I add a ContentSizeFitter script to the Viewport/Content and try the different "Vertical Fit" settings I am unable to place the buttons where I specified and have it possible to scroll the button into view and keep it there.

    Can someone tell me, is this a bug or am I doing something wrong?

    (Unity 2017.3.0f3)
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If I understood your question correctly, you want a chunk of space between the 2 buttons?

    I was able to achieve something like that, using an empty game object in between the 2 buttons, as well as a vertical layout group on the content portion + a content size fitter.

    I also used some layout elements on the 2 buttons and the empty game object.

    I'm not 100% confident which part(s) made it work, but perhaps you can experiment with something like that, if that's what you were asking :)
     
  3. mrpmorris

    mrpmorris

    Joined:
    Dec 25, 2012
    Posts:
    50
    Adding ContentSizeFitter to the Content object (with VerticalFit = PreferredSize) and then adding a VerticalLayoutGroup script as well fixed the problem. It allowed me to put a large empty Panel between the two buttons.

    Thanks!
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool :) You're welcome. Glad I could help.