ConstraintLayout views in top left corner

前端 未结 5 1782
无人共我
无人共我 2020-11-22 04:21

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

5条回答
  •  星月不相逢
    2020-11-22 05:14

    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:

提交回复
热议问题