Android-ConstraintLayout使用笔记

来源:互联网 发布:英语打字软件 编辑:程序博客网 时间:2024/05/21 09:33

自AndroidStudio2.3以来,ConstraintLayout得到了一个很大优化,创建的Activity的xml布局,根布局都是用的ConstraintLayout,所以有必要了解一下ConstraintLayout了

  • ConstraintLayout相当于一个特殊的RelativeLayout,一些常用的属性介绍
// 与xxx控件顶部对齐app:layout_constraintTop_toTopOf="@+id/xxx"// 与xxx控件底部对齐app:layout_constraintBottom_toBottomOf="@+id/xxx"// 与xxx控件左边对齐app:layout_constraintLeft_toLeftOf="@+id/xxx"// 与xxx控件右边对齐app:layout_constraintRight_toRightOf="@+id/xxx"

image铺满
image居中

  • 一些常用属性
// 当前控件顶部与xxx控件底部对齐app:layout_constraintTop_toBottomOf="@+id/xxx"// 当前控件底部与xxx控件顶部对齐app:layout_constraintBottom_toTopOf="@+id/xxx"// 当前控件左边与xxx控件右边对齐app:layout_constraintLeft_toRightOf="@+id/xxx"// 当前控件右边与xxx控件左边对齐app:layout_constraintRight_toLeftOf="@+id/xxx"// 距离上边的View 5dpandroid:layout_marginTop="5dp"// 距离下边的View 5dpandroid:layout_marginBottom="5dp"// 距离左边的View 5dpandroid:layout_marginLeft="5dp"// 距离右边的View 5dpandroid:layout_marginRight="5dp"/* * 为为了适配一些地区从右往左的阅读习惯.从右往左时,起始边(start)为右边,结束边(end)为左边,android:layout_marginStart为距离右边的View;从左往右时,起始边(start)为左边,结束边(end)为右边,android:layout_marginStart为距离左边的View。为了匹配多地区时,应用start/end替代left/right */// 距离起始边的View 5dpandroid:layout_marginStart="5dp"// 距离结束边的View 5dpandroid:layout_marginEnd="5dp"// 与xxx控件起始边对齐app:layout_constraintStart_toStartOf="@+id/xxx"// 与xxx控件结束边对齐app:layout_constraintEnd_toEndOf="@+id/xxx"// 当前控件的起始边与xxx控件的结束边对齐app:layout_constraintStart_toEndOf="@+id/xxx"// 当前控件的结束边与xxx控件的起始边对齐app:layout_constraintEnd_toStartOf="@+id/xxx"
  • ConstraintLayout作为一个类似iOS的约束布局,自然拥有一些约束布局用的按钮,一些常用按钮的作用:image作用:切换显示视图。image作用:显示/隐藏约束。image作用:自动添加约束,效果如下:image
    image作用:清除约束(慎用),效果如下:imageimage作用:自动添加约束,效果如下:imageimage image一直不明白这两张图的按钮使用,有知道的大神求点拨!!!
0 0
原创粉丝点击