Search code examples
androidxmlandroid-studioandroid-layoutandroid-motionlayout

Is it possible to move A layout towards left so that other side of screen can be visible?


Actually, I am trying to build a game in which the scene is outside the screen. I want my screen to scroll towards the right so that my that scene comes to the screen when I click any button. I am doing it using motionLayout in Android studio. Can any one help?


Solution

  • I motionLayout you would constrain the view fully on screen in one state and fully off screen in the other. Than the transition would "slide" the view in.

    The typical problem when people do this with MotionLayout is how to constrain a "full size view" outside the bounds of the screen.

    There are several ways to accomplish this 2 are:

    1. used layout_width="match_parent" & layout_constraintLeft_toRightOf="parent"
    2. use layout_width="0dp" & layout_constraintLeft_toRightOf="parent" andlayout_constraintWidth_percent="1"

    The key is you are constraining the left side of the view to the right side of the parent.

    This is an example of layout the constraints for slide in.