【错误记录】约束布局报错 ( Missing Constraints in ConstraintLayout. This view is not constrained. It only has )
2023-06-13 09:18:07 时间
文章目录
一、报错信息
约束布局中 , 如果不给组件添加约束 , 就会报如下错误 :
Missing Constraints in ConstraintLayout
This view is not constrained. It only has designtime positions,
so it will jump to (0,0) at runtime unless you add the constraints
The layout editor allows you to place widgets anywhere on the canvas,
and it records the current position with designtime attributes (such as layout_editor_absoluteX).
These attributes are not applied at runtime, so if you push your layout on a device,
the widgets may appear in a different location than shown in the editor.
To fix this, make sure a widget has both horizontal and vertical
constraints by dragging from the edge connections.
Issue id: MissingConstraints Vendor: Android Open Source Project Contact:
https://groups.google.com/g/lint-dev
Feedback: https://issuetracker.google.com/issues/new?component=192708
二、解决方案
1、手动添加约束 ( 推荐 )
Design 界面拖动添加约束操作 : 手动拖动 布局上下左右的 约束按钮 , 添加约束 ;
Code 代码添加约束 : 在代码中 , 添加 如下 上下左右的 约束 ;
app:layout_constraintBottom_toTopOf=“@+id/guideline3” app:layout_constraintEnd_toEndOf=“parent” app:layout_constraintStart_toStartOf=“parent” app:layout_constraintTop_toTopOf=“parent”
组件约束完整示例如下 :
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView1"
android:name="kim.hsl.livedatademo.Fragment1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
2、自动添加约束
使用 Design 面板中的 Infer Constraints 工具 , 可以自动为组件添加约束 ;
相关文章
- 日常IT技巧总结_it工作写经验总结
- IT和业务领导者在制定云计算战略时可能会犯的10个常见错误
- 行业首家!地平线征程5获颁CCRC IT产品信息安全认证EAL3+证书
- 【错误记录】Android Studio 编译报错 ( Cannot use connection to Gradle distribution . as it has been stopped. )
- 【错误记录】发布 Flutter 插件包报错 ( It‘s strongly recommended to include a “homepage“ or “repository“ field )
- it Linux软件编程的CRTIT框架实践(linuxcrt)
- IT之家鸿蒙OS原生版 1.10 上架:重大顺畅度优化/滑动切换板块/支持平板电脑……
- 播客 Oracle传智播客:实现IT技能提升之梦!(oracle传智)
- 微软云SQL Server——让IT开发变得更加简单(微软云sqlserver)
- 鸟哥的Linux私房菜:新一代IT技术感受(鸟哥的linux私房菜 第四版)
- 了解Oracle的在IT行业的重要性(itl oracle)
- Oracle大赛:成就IT之星(oraclerace)
- MySQL中的user字段重要的用户信息存储 NoteAs an AI language model I can generate articles but it might not be 100 accurate
- 球CLOUDOracle云计算 改变全球IT趋势(oracle全)
- Oracle免费套餐大大提升你的IT性能(oracle免费套餐)
- 70年代末Oracle见证了IT快速发展的奇迹(70年代末oracle)
- 解决方法MySQL无法连接到指定地址Note from the authorPlease note that this title is not exactly 25 words but it is the most effective and informative title without being too wordy
- Oracle Rname利用精耕细作挖掘更大IT价值(oracle rname)