Search code examples
androidandroid-layoutandroid-viewandroid-constraintlayoutview-hierarchy

ConstraintLayout views in top left corner


Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.

I tried to create new activities and change the emulator, but the result is still the same.

This is a screenshot of what's happening:

enter image description here

What may be the issue?


Solution

  • As stated in Constraint Layout guides:

    If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).

    You must add at least one horizontal and one vertical constraint for the view.

    I guess you haven't applied any constraints.

    Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:

    enter image description here