Search Unity

ScrollRect : always 3 screens wide, regardless of aspect ratio

Discussion in 'UGUI & TextMesh Pro' started by Mycroft, Feb 22, 2017.

  1. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    Expected
    I want a ScrollRect for 3 screen-widths of content.
    The user is able to press a button to have the it automatically switch between them (no dragging)
    The 3 screens need to match the Device's width

    Issue
    When I switch from iPhone 5 aspect ratio to a wider ratio, the HorizontalScrollRect RectTransform Right stays -1280. The elements inside change width (i suspect to accommodate the new aspect ratio) but are not wide enough to cover the entire screen.

    I've tried a bunch of different layout setups, but not finding anything that matches the elements to the screen size. I would do it in code, but the size is somehow related to the Canvas scaler in a way that i'm not easily seeing.


    The Canvas is setup to use the (very narrow) iPhone 5 Portrait Mode as the base resolution.

    upload_2017-2-22_9-55-13.png



    HorizontalScroll
    upload_2017-2-22_10-31-46.png


    HorizontalScrollRect (the content for the ScrollRect)
    upload_2017-2-22_10-33-37.png



    And this is one of the screens
    upload_2017-2-22_10-35-38.png
     
  2. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    The element when in iPhone 5 resolution
    upload_2017-2-22_11-11-25.png

    The element when switching to iphone 6 aspect ratio
    upload_2017-2-22_11-12-47.png
     
  3. Jesper-Nielsen

    Jesper-Nielsen

    Joined:
    Nov 14, 2013
    Posts:
    95
    What happens if you make the canvas scale match width only?
     
  4. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    You were absolutely right, Thank you.

    But what if I really did need to match to ether Height/Width and still get the right screen width?
     
  5. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    Found the correct solution for anyone who comes through later

    The Anchor needed to be set to 3x the screen width and there should be zero offset from there (this is where the aspect ratio changes threw it off)

    upload_2017-2-23_15-57-40.png
     
    Jesper-Nielsen likes this.