Centering In MojoX

About Monkey 2 Forums Monkey 2 Programming Help Centering In MojoX

This topic contains 2 replies, has 2 voices, and was last updated by  Abe _King_ 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12853

    Abe _King_
    Participant

    So I know there are ways to do “top left right bottom” but I’m not aware of any way or method to center views…

    What I’m trying to do: I have a view which takes up a dynamic dimension. I add child components to it AddView(…) of unknown sizes(to me). I want them to be viewed in the middle&center of the screen. This isn’t working though!

    Is there a way to achieve this?
    https://s14.postimg.org/cnwslzapt/example.png

    Where the red lines are equal and the green lines are equal

    #12857

    Mark Sibly
    Keymaster

    Here’s a little demo of centering a view within another view  – in this case, a GridView within a window.

    The key here is set the view want to be centered’s layout to “float” and its gravity to .5,.5. This causes the view to ‘float’ in the center of it’s frame. Ditto you can uses different gravity values to float at top left, bottom right, bottom center etc.

    (Note: I found a little bug in GridView while doing this that causes overlap between child gadgets in a gridview – fixed in develop branch).

    #12871

    Abe _King_
    Participant

    Thank you! I would have never figured this out haha. This has helped me a lot to learn more about mojox, so that’s great news. Very much appreciated 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.