近期一直在搞项目的优化工作,奉行布局嵌套不超过三层的原则,项目中各种xml布局文件,我已经做到尽可能的优化,但是仍然有些无法做到,于是乎,猛然想到之前在宏洋大神那里看到的一篇博客,写的是关于google新出的ConstraintLayout使用方法,当时只是粗略带过,现如今仔细研究了一下午,如获至宝,不禁感叹:老哥666!,在此贴上链接:
https://blog.csdn.net/guolin_blog/article/details/53122387,文章中讲解的很清楚,除了如何让view居中显示,那么这里我就来贴上然view居中显示的方法
1,相对整个ConstraintLayout居中:
(1) 水平居中:
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
(2)垂直居中:
app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"
2,相对于某一个控件居中:
app:layout_constraintTop_toTopOf="@+id/view" app:layout_constraintBottom_toBottomOf="@id/view" app:layout_constraintStart_toStartOf="@id/view" app:layout_constraintEnd_toEndOf="@id/view"希望对观看者有一点点帮助,本人就十分开心啦。。