ConstraintLayout views in top left corner

前端 未结 5 1684
无人共我
无人共我 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:02

    When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier

    In other words, the View will "stay where you leave it" until you add constraints.

    The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.

    And it may be troublesome for beginners because

    a missing constraint won't cause a compilation error

    However

    the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features

    More details

提交回复
热议问题