当前位置: 首页 > news >正文

ConstraintLayout是完美的布局吗?

非也!

     <TextViewandroid:id="@+id/tv_tittle_msg"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="16dp"android:layout_marginRight="16dp"android:layout_marginTop="8dp"android:text="@string/string_sss"android:textColor="@color/color_basefunction_2F353B"android:textSize="14sp"app:layout_constraintStart_toStartOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toBottomOf="@+id/tv_tittle" />

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

之后

layout_marginHorizontal   这个属性

不起作用

在使用 ConstraintLayout 时,app:layout_constraintStart_toStartOf="parent"app:layout_constraintEnd_toEndOf="parent" 会将视图的水平位置完全居中,这种约束方式会覆盖 layout_marginHorizontal 的作用。

这是因为 layout_marginHorizontal 的设置逻辑是为左右外边距添加间距,而水平居中对齐(通过上述约束)已经将视图的水平位置固定,因此左右的 margin 无法生效。

解决办法有很多,网络各种什么guidelinelayout_constraintWidth_default、Barrier、使用 Padding 替代 Margin

都没有必要,外面再包一层LinearLayout就行了

    <LinearLayoutandroid:id="@+id/ll_tittle_msg"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="16dp"android:layout_marginRight="16dp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/tv_tittle"><TextViewandroid:id="@+id/tv_tittle_msg"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="8dp"android:text="@string/string_xxx"android:textColor="@color/color_basefunction_2F353B"android:textSize="14sp"/></LinearLayout>

http://www.lryc.cn/news/509361.html

相关文章:

  • 39.在 Vue3 中使用 OpenLayers 导出 GeoJSON 文件及详解 GEOJSON 格式
  • Feign的调用demo 和 EnableFeignClients的包名
  • 简化开发流程:如何通过 JDBC 自动生成符合 Java 命名规范的实体类
  • W25Q128存储器详解
  • Vite系列课程 | 11. Vite 配置文件中 CSS 配置(Modules 模块化篇)
  • Everspin代理MR25H10CDFR存储MRAM
  • cesium小知识:使用 EntityCollection的方法
  • Java 日志类库
  • 【Unity3D】Particle粒子特效或3D物体显示在UGUI上的方案
  • 有没有检测吸烟的软件 ai视频检测分析厂区抽烟报警#Python
  • 《鸣潮》游戏运行时弹出“xinput1_3.dll文件缺失”错误的处理方法,“xinput1_3.dll文件缺失”详解!
  • 大模型应用—HivisionIDPhotos 证件照在线制作!支持离线、换装、美颜等
  • 解决Ubuntu下无法装载 Windows D盘的问题
  • 一体成型电感
  • Reed-Muller(RM)码之编码
  • 【蓝桥杯——物联网设计与开发】基础模块8 - RTC
  • 聚类算法DBSCAN 改进总结
  • uniapp开发微信小程序实现获取“我的位置”
  • java中两个系统进行非对称加密,两个系统的公私钥可以用一套吗?
  • 无人设备遥控器之定向天线篇
  • 【电路笔记 信号】Metastability 平均故障间隔时间(MTBF)公式推导:进入亚稳态+退出亚稳态+同步器的可靠性计算
  • 计算机视觉:原理、分类与应用
  • Vue.js组件开发-使用watch进行深度观察
  • 明厨亮灶系统
  • 虚幻引擎结构之AActor
  • 基于JAVA+SpringBoot+Vue的制造装备物联及生产管理ERP系统
  • JAVA HTTP压缩数据
  • VSCode 配置远程连接免密登录 插件
  • VIVO C++开发面试题及参考答案
  • Unity3D用正则判断身份证号或邮箱