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

Scroll View move back on the spot

Discussion in 'UGUI & TextMesh Pro' started by siddharth3322, Sep 22, 2015.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    Basically for my game I am using Unity UI Scroll Rect. I go through video related to that but cant able to solve my problem.

    My scroll view not able to provide scrolling functionality. when I release my finger it moves back at same time. Following video link gives you more idea about this.

    https://www.dropbox.com/s/ermxkk919lulb3v/ScrollBugVideo.mov?dl=0

    I have done nothing special in creating my scroll hierarchy. No extra script was added in inspector. If you want any more information you want from my side then I am available always.

    One thing I want to mention, if I add only single image in child then scrollview works perfectly.
     
  2. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    EDIT : If I give correct value manually here then my scroll view working correctly. But my content is dynamic then how to deal with it?

    Screen Shot 2015-09-22 at 9.56.00 pm.png
     
  3. BinaryX

    BinaryX

    Joined:
    Aug 4, 2014
    Posts:
    55
    From what i can see in your video, you have something like this

    QuizPanel
    -- ContentScrollView
    ----- ContentPanel
    --------- Image
    --------- Image
    --------- Image

    When you add dinamically an Image the the ContentPanel, you also need to modify its height to fit the new element. Start with height 0 and then when you add a new Image you simply add the height of the image to the height of the ContentPanel ( and you should probably add several more offset pixels for the gaps in between images ). This way, after you added all elements to the scrolling list it will have proper dimensions and it should work as intended.

    If you want to remove all the items from the list, delete them and make the height of the ContentPanel 0 again. Then start over.
     
  4. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    @BinaryX , Thanks for this useful info. You are completely right about this.
    If I want to change height of content panel dynamically then what is the way for it?
     
  5. BinaryX

    BinaryX

    Joined:
    Aug 4, 2014
    Posts:
    55
    If you have a LayoutGroup (Vertical or Horizontal) i don't think you are able to change those values directly, so you will need to use another component (Content Size Fitter i think it's called ) that does this for you.

    Without a LayoutGroup, you can access the "sizeDelta" of the RectTransform and change that value. sizeDelta.x is the width and sizeDelta.y is the height.
     
    abductor likes this.