ConstraintLayout 的使用

简介: ConstraintLayout 的使用

1.定位位置

控件的那一边和 另一个控件的那一边对齐

  • layout_constraintLeft_toLeftOf  左边和左边对齐
  • layout_constraintLeft_toRightOf  左边和右边对齐
  • layout_constraintRight_toLeftOf  右边和左边对齐
  • layout_constraintRight_toRightOf
  • layout_constraintTop_toTopOf
  • layout_constraintTop_toBottomOf
  • layout_constraintBottom_toTopOf
  • layout_constraintBottom_toBottomOf
  • layout_constraintBaseline_toBaselineOf
  • layout_constraintStart_toEndOf
  • layout_constraintStart_toStartOf
  • layout_constraintEnd_toStartOf
  • layout_constraintEnd_toEndOf

 

2.居中对齐

同时设置:


水平居中:


app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"


竖直居中:

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintBottom_toBottomOf="parent"


偏移

  • layout_constraintHorizontal_bias  左右偏移   取值范围  0~1
  • layout_constraintVertical_bias      上下偏移  取值范围  0~1


3.margin的设置

同时使用

android:layout_marginXXX="30dp"

app:layout_constraintXXX_toBottomOf="@+id/insert"


目录
相关文章
|
开发工具 Android开发
AndroidX到底是啥?
AndroidX到底是啥?
188 0
|
8月前
|
Android开发 UED 开发者
Android 中的 LinearLayout 布局
Android 中的 LinearLayout 布局
|
8月前
|
Android开发 开发者
深入了解 Android 中的 RelativeLayout 布局
深入了解 Android 中的 RelativeLayout 布局
|
Android开发
Android ConstraintLayout
Android ConstraintLayout
114 0
|
Java Android开发 Kotlin
Android转AndroidX
公司项目多,有些事java,有些是kotlin,有些是Android,有些是AndroidX,一些依赖和依赖库的更新使得调用的方法等不同,导致功能同步时效率及极其低下,于是打算把Android项目转成AndroidX。
|
XML API Android开发
关于什么是AndroidX(二)
迁移成功后,我们先build 一下项目,看看有没有报错,有时会报错,报错的地方可以通过控制台build选项卡中看到,有些是无法自动转换的,需要手动转化,比如布局xml中的控件包名,它会保留迁移之前的包名,这个时候我们手动使用AndroidX对应包明即可。
179 0
关于什么是AndroidX(二)
|
XML 机器人 数据格式
ConstraintLayout简单效果
ConstraintLayout简单效果
359 0
ConstraintLayout简单效果
|
API Android开发 开发者
关于什么是AndroidX(一)
Android 问世的时候,估计连开发者自己都没想到它会如此成功,因为一开始不可能就将API考虑得非常周到,以至于随着Android系统版本的不断迭代更新,每个版本都会新增加入很多新的API,但是新增的API在老版本中是不存在的,这里就出现了一个向下兼容的问题。
319 0
|
XML Android开发 数据格式
ConstraintLayout 想说爱你不容易 (二)
日常补漏,学习一下 ConstraintLayout 基本用法!
513 0
ConstraintLayout 想说爱你不容易 (二)
|
测试技术 Android开发
ConstraintLayout 想说爱你不容易!
      ConstraintLayout 约束布局 的发布已经很长时间了,小菜用的比较少,测试时看到同事用的 ConstraintLayout 布局方式编辑的 xml,觉得有必要学习一下,并记录一下小菜在学习过程中遇到的小问题。
1246 0