左上角的ConstraintLayout视图 [英] ConstraintLayout views in top left corner
问题描述
每次我在ConstraintLayout
中创建诸如Button
和TextView
的视图时,它们都会卡在顶部角落,而不是我放置在它们的位置.
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:
可能是什么问题?
推荐答案
如约束布局指南:
如果在设备上运行布局时视图没有约束,则将其绘制在位置[0,0](左上角).
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:
这篇关于左上角的ConstraintLayout视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!