一分钟学会ConstraintLayout(转载)
原文地址:https://www.v2ex.com/t/287863
最近更新了Android Studio,突然发现xml中的布局已经变成了ConstraintLayout,于是搜了一篇文章看一下
确实想题目说的,一分钟学会~
首先来看一个实例:
我们举一个例子来看具体是什么样的:
Button1:app:layout_constraintBottom_toTopOf="@id/iv_head"()
我们把这个属性拆开来看, constraintBottom 指的本身的底部,即 Button1 的底部, toTopOf 是指某某的顶部,那么这句话的意思就是
button1的底部,并且在iv_head的顶部
Android开发文档原文是这样的:
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 之从属性角度理解布局
- 一分钟学会 ConstraintLayout 之从属性角度理解布局
- 一分钟学会 ConstraintLayout 之从属性角度理解布局
- 一分钟学会collectionView自定义layout(一)
- Android新特性介绍,ConstraintLayout完全解析(吕万友:转载)
- 一分钟学会collectionView自定义layout(二、圆形布局)
- 【转载】Android新特性介绍,ConstraintLayout完全解析
- 使用ConstraintLayout构建一个灵活的布局
- 动态图解&实例 ConstraintLayout Chain
- Android新特性介绍,ConstraintLayout完全解析
- Build a Responsive UI with ConstraintLayout
- 依赖ConstraintLayout报错:Could not find com.android.support.constraint:constraint-layout:1.0.0-beta5
- (转载)俞敏洪一分钟励志演讲
- com.android.support.constraint:constraint-layout:1.0.2
- constraint auto layout
- 为什么ConstraintLayout代替其他布局?
- 七天学会ASP.NET MVC (五)——Layout页面使用和用户角色管理
- iOS开发之autoLayout constraint
- ConstraintLayout完全解析
- Memory Layout for Multiple and Virtual Inheritance (转载--By Edsko de Vries, January 2006)