picture
此视图不受约束,它只有设计时位置,因此除非添加约束,否则它将跳转到(0,0
布局编辑器允许您将小部件放置在画布上的任何位置,并且它使用设计时属性记录当前位置(例如layout_editor_absolute X。)这些属性不会在运行时应用,因此如果您将布局推送到设备上,小部件可能会出现在与编辑器中显示的位置不同的位置。要解决此问题,通过从边缘连接拖动,确保小部件同时具有水平和垂直约束
picture
此视图不受约束,它只有设计时位置,因此除非添加约束,否则它将跳转到(0,0
布局编辑器允许您将小部件放置在画布上的任何位置,并且它使用设计时属性记录当前位置(例如layout_editor_absolute X。)这些属性不会在运行时应用,因此如果您将布局推送到设备上,小部件可能会出现在与编辑器中显示的位置不同的位置。要解决此问题,通过从边缘连接拖动,确保小部件同时具有水平和垂直约束
5条答案
按热度按时间vcirk6k61#
解决这个问题很简单。只需点击小部件(例如按钮或文本框等),然后点击“推断约束”按钮。您可以在所附图片或此Youtube链接中看到:https://www.youtube.com/watch?v=uOur51u5Nk0
ogsagwnx2#
您可能拥有具有以下属性的小部件:
tools
命名空间只在开发时使用,并将在安装apk时删除,因此所有您的布局可能会出现在左上角的位置一个在另一个之上。查看Tools Attributes Reference要解决此问题,请执行以下操作:您应该使用布局约束,如:
您可以查看ConstraintLayout和Build a Responsive UI with ConstraintLayout的文档以了解更多详细信息
编辑:
从您发布的picture中,我尝试使用以下代码添加适当的约束,以便TextView处于Center位置:
5hcedyr03#
ConstraintsLayout”中缺少约束。此错误是由于未定义的约束引起的。要修复此错误,请单击小部件(ex text、按钮等),然后单击活动屏幕上方的推断约束。希望这样可以解决您的查询
ycggw6v24#
enter image description here
首先点击组件树中线性布局,然后点击活动屏幕中眼睛符号右侧推断约束
r1zk6ea15#
如果您确实为视图指定了有效的约束,但Android Studio仍然向您推送了一个“幻影”
MissingConstraint
错误,请尝试以下操作:1.清理项目(* 生成〉清理项目 )
1.关闭项目( 文件〉关闭项目 *)
*移除项目的
.idea/
目录.idea/
签入源代码管理,请回滚它们*打开您的项目
重建您的项目( 重建〉重建项目 *)
这个神圣的净化仪式帮助我摆脱了这个“幻影”错误,以及过去许多其他怪异的错误,所以我希望它也能帮助你。