ConstraintLayout views in top left corner

hassanito hajj picture hassanito hajj · Mar 4, 2017 · Viewed 37.3k times · Source

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?

Answer

azizbekian picture azizbekian · Mar 4, 2017

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