Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to dynamically resize the "Content" field in "Viewport" in "Scroll View"?

Discussion in 'UGUI & TextMesh Pro' started by hashmm2, Mar 23, 2020.

  1. hashmm2

    hashmm2

    Joined:
    Oct 21, 2019
    Posts:
    16
    I'm going to have various bits of text pulled from a database to be displayed in the text field within the scroll view. The issue is there is differing amounts of text for different objects so I was wondering if there was some way to automate it instead of manually inputting the height (which will be a trial and error thing).

    I did find a couple posts addressing this issue by using the "Content Size Fitter" and setting "Virtual Fit" to "Preferred Size" but that makes it smaller back to the default size. Any idea what I'm doing wrong?

    I've attached an image of the hierarchy below and what my text field looks like.
     

    Attached Files:

  2. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I am currently looking into this too and you posted at the right time. I dont have an answer at this either.
    I have a datalist that varies from 11 to 100 rows so I made the content window large. When there are only 11 rows the user can scroll a long time and end with a window that is empty. This drove to research this content size change. It is currently #3 on my todo-s. I watch with baited breath till then.
    Thank for posting this question.
     
  3. hashmm2

    hashmm2

    Joined:
    Oct 21, 2019
    Posts:
    16
    Do let me know over here if you happen to come across a solution, I'll do the same.
     
  4. hashmm2

    hashmm2

    Joined:
    Oct 21, 2019
    Posts:
    16
    @giantkilleroverunity3d I think I've found a workout for my particular issue, gotta test is thoroughly.

    Here's What I did
    Scroll View
    -> Viewport
    ---> Content (Vertical Layout Group, child control size width/height and child force expand width/height + content size fitter with vertical fit preferred size)