ConstraintLayout

在 Android 开发中,我们通常是手写布局,很少会用拖动来写布局,虽然 ConstraintLayout 在 I/O 上以拖动来展现了各种功能,我估计在以后开发中,程序员还是习惯手撸代码。

我自己试着拖着用了一下,用得不是很明白 ,而且用起来效果不是很好。

那么
直接上手撸了一下~~~

其实很简单

Button1:app:layout_constraintBottom_toTopOf="@id/iv_head"

我们把这个属性拆开来看, constraintBottom 指的本身的底部,即 Button1 的顶部, toTopOf 是指 ImageView 的顶部,那么这句话的意思就是
Aligns the bottom of the desired view to the top of another.(官方原文)
翻译一下就是 Button1 的底部要和 ImageView 的顶部对齐

Button1 app:layout_constraintRight_toLeftOf="@id/iv_head"
根据上面的规则我们就知道 Button1 的右边要和 ImageView 的左边对齐。

其实很简单就是说两个 View 的某个方位要对齐

没了,就这么简单,其它属性可以举一反三,它比 RelativeLayout 控制起来更加得以就手。

  • layout_constraintTop_toTopOf  —  Align the top of the desired view to the top of another.
  • layout_constraintTop_toBottomOf  —  Align the top of the desired view to the bottom of another.
  • layout_constraintBottom_toTopOf  —  Align the bottom of the desired view to the top of another.
  • layout_constraintBottom_toBottomOf  —  Align the bottom of the desired view to the bottom of another.
  • layout_constraintLeft_toTopOf  —  Align the left of the desired view to the top of another.
  • layout_constraintLeft_toBottomOf  —  Align the left of the desired view to the bottom of another.
  • layout_constraintLeft_toLeftOf  —  Align the left of the desired view to the left of another.
  • layout_constraintLeft_toRightOf  —  Align the left of the desired view to the right of another.
  • layout_constraintRight_toTopOf  —  Align the right of the desired view to the top of another.
  • layout_constraintRight_toBottomOf  —  Align the right of the desired view to the bottom of another.
  • layout_constraintRight_toLeftOf  —  Align the right of the desired view to the left of another.
  • layout_constraintRight_toRightOf  —  Align the right of the desired view to the right of another.
  • If desired, attributes supporting start and end are also available in place of left and right alignment.

到此,你已经掌握了一大半的 ConstraintLayout 知识点

还有其它的一些属性
app:layout_constraintStart_toEndOf
意思就是 Button 的开始部分(从左往右看,开始部分就是 Button 的左边)与 ImageView 的右边是对齐的。
app:layout_constraintStart_toStartOf
这个就是说 Button 的左边与 ImageView 的左边是对齐的

不知道为什么上面已经出的属性能够满足布局需要了,为什么还要再出 start 和 end 的。

原文:

一分钟学会 ConstraintLayout

http://chenxiaojian.net/quickly-learn-constraintlayout.html

 

2 回复  |  直到 2016-06-24 11:17:32 +08:00

 
    1
 

jianqiu   2016-06-24 10:04:21 +08:00

 
start 和 end 都是针对某些国家习惯从右到左布局的..保持这种兼容性
 
    2
 

ChenPing   2016-06-24 11:17:32 +08:00

 
@jianqiu 原来如此

一分钟学会 ConstraintLayout 之从属性角度理解布局的更多相关文章

  1. 一分钟学会ConstraintLayout(转载)

    原文地址:https://www.v2ex.com/t/287863 最近更新了Android Studio,突然发现xml中的布局已经变成了ConstraintLayout,于是搜了一篇文章看一下 ...

  2. PHP学习过程_Symfony_(3)_整理_十分钟学会Symfony

    这篇文章主要介绍了Symfony学习十分钟入门教程,详细介绍了Symfony的安装配置,项目初始化,建立Bundle,设计实体,添加约束,增删改查等基本操作技巧,需要的朋友可以参考下 (此文章已被多人 ...

  3. 30 分钟学会 Flex 布局

    30 分钟学会 Flex 布局 有酒   617 人赞同了该文章 为什么我要写这一篇关于 Flex 布局的教程? 因为它十分简单灵活,区区简单几行代码就可以实现各种页面的的布局,以前我在学习页面布局的 ...

  4. 三分钟学会@Autowired@Qualifier@Primary注解

    三分钟学会@Autowired@Qualifier@Primary注解 2018.10.08 20:24 154浏览 今天主要简单的跟大家介绍一下spring自动装配相关的@Autowired,@Qu ...

  5. 5分钟学会使用Less预编译器

    5分钟学会使用Less预编译器 Less是什么? LESS CSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法为CSS赋予了动态语言的特性,如变量.继承.运算.函数等,更方便 ...

  6. 【grunt第二弹】30分钟学会使用grunt打包前端代码(02)

    前言 上一篇博客,我们简单的介绍了grunt的使用,一些基础点没能覆盖,我们今天有必要看看一些基础知识 [grunt第一弹]30分钟学会使用grunt打包前端代码 配置任务/grunt.initCon ...

  7. 《量化投资:以MATLAB为工具》连载(2)基础篇-N分钟学会MATLAB(中)

    http://www.matlabsky.com/thread-43937-1-1.html   <量化投资:以MATLAB为工具>连载(3)基础篇-N分钟学会MATLAB(下)     ...

  8. 《量化投资:以MATLAB为工具》连载(1)基础篇-N分钟学会MATLAB(上)

    http://blog.sina.com.cn/s/blog_4cf8aad30102uylf.html <量化投资:以MATLAB为工具>连载(1)基础篇-N分钟学会MATLAB(上) ...

  9. [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)

    [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例) 踏雁寻花 发表于 2015-8-23 23:31:28 https://www.itsk.com/thread-35 ...

随机推荐

  1. 在crontab中执行shell脚本的问题

    crontab中记录的编写比较简单,下面是一个示例: * * * /app/tpssapp/ftpsrc/tools/statTables/statTables.sh > /app/tpssap ...

  2. hiho 1612

    emmmmm?A不了?90分是什么鬼 #include<cstdio> #include<cstdlib> #include<vector> #include< ...

  3. sublime text3安装以及插件配置教程

    http://blog.csdn.net/feizaosyuacm/article/details/54729891 本文是安装的Sublime Text3是portable version(可移动版 ...

  4. WebStorm的下载与安装

    百度搜索: 链接:http://www.jetbrains.com/webstorm/ 链接:http://www.jetbrains.com/student/ 学生免费授权计划 请从正规来源下载软件 ...

  5. BZOJ1563 NOI2009 诗人小G【决策单调性优化DP】

    LINK 因为是图片题就懒得挂了 简要题意:有n个串,拼接两个串需要加一个空格,给你l和p,问你拼接后每个串的总长减l的绝对值的p次方的最小值 首先打表发现一下这题是决策单调的对于所有数据都成立就当他 ...

  6. 推荐近乎免费的调试神器——OzCode

    当一只断点打在 Visual Studio 的代码编辑器中,程序命中断点的那一刻,调试才刚刚开始……这个时候忙碌的手在键盘和鼠标之间来回跳跃,试图抓住每一次单步执行带来的状态改变. 如果命中断点的那一 ...

  7. Hangfire 任务调度

    Hangfire是一个开源且商业免费使用的工具函数库.可以让你非常容易地在ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows Ser ...

  8. JS脚本不能运行

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/moqiang02/article/details/25898295 这段时间在做前端的动态页面,出了 ...

  9. ecmall类关系图(转)

  10. (转)如何制作nodejs,npm “绿色”安装包

      摘自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=8625039&id=3817492       由于公司环境 ...