美文网首页
Android ConstraintLayout不完全笔记

Android ConstraintLayout不完全笔记

作者: 白云无尽_ | 来源:发表于2019-03-20 10:13 被阅读0次

简介

ConstraintLayout在2016 年 Google I/O 推出,是一种新型的布局方式。本质上是为各个控件建立相对关系,可以看做是RelativeLayout的升级版,避免了多个ReletiveLayout的嵌套使用。

引入

implementation 'com.android.support.constraint:constraint-layout:latest.release

核心使用方式

app:layout_constraintTop_toBottomOf="parent" <!--顶部与某元素底部对齐-->
app:layout_constraintBottom_toTopOf="parent" <!--底部与某元素顶部对齐-->
app:layout_constraintStart_toStartOf="parent"<!--左边与某元素左边对齐-->
app:layout_constraintEnd_toEndOf="parent"<!--右边与某元素右边对齐-->
<!--控制对齐距离-->
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"

GuideLine(参考线)

image.png

通过参考线,可以实现百分比定位。


image.png

从而避免复杂的布局嵌套。

特殊点

0dp-与wrapcontent类似,但不完全相同。

注意事项

使用RecycleView时底部一定要添加约束,否则会可能出现显示不全的情况。

相关文章

网友评论

      本文标题:Android ConstraintLayout不完全笔记

      本文链接:https://www.haomeiwen.com/subject/xoiamqtx.html