源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android新布局方式ConstraintLayout快速入门教程

  • 时间:2022-09-21 06:02 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android新布局方式ConstraintLayout快速入门教程
[b]前言[/b] 在Android开发中,我们通常是手写布局,很少会用拖动来写布局,虽然ConstraintLayout在I/O上以拖动来展现了各种功能,我估计在以后开发中,程序员还是习惯手撸代码。 我自己试着拖着用了一下,用得不是很明白 ,而且用起来效果不是很好。 那么 直接上手撸了一下~~~ 其实很简单 [img]http://files.jb51.net/file_images/article/201705/2017526111637256.jpg?2017426111712[/img] [img]http://files.jb51.net/file_images/article/201705/2017526111733505.png?2017426111744[/img] [code]Button1:app:layout_constraintBottom_toTopOf="@id/iv_head"[/code] 我们把这个属性拆开来看,constraintBottom指的本身的底部,即Button1的顶部,toTopOf是指ImageView的顶部,那么这句话的意思就是 Aligns the bottom of the desired view to the top of another.(官方原文) 翻译一下就是Button1的底部要和ImageView的顶部对齐 [code]Button1 app:layout_constraintRight_toLeftOf="@id/iv_head"[/code] 根据上面的规则我们就知道Button1的右边要和ImageView的左边对齐。 其实很简单就是说两个View的某个方位要对齐 没了,就这么简单,其它属性可以举一反三,它比RelativeLayout控制起来更加得以就手。 [list] [*]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. [/*] [/list] 到此,你已经掌握了一大半的ConstraintLayout知识点 [b]还有其它的一些属性[/b] [code]app:layout_constraintStart_toEndOf[/code] 意思就是Button的开始部分(从左往右看,开始部分就是Button的左边)与ImageView的右边是对齐的。 [code]app:layout_constraintStart_toStartOf[/code] 这个就是说Button的左边与ImageView的左边是对齐的 不知道为什么上面已经出的属性能够满足布局需要了,为什么还要再出start和end的。 [b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部