就个人使用 ConstraintLayout 布局经验,逐步记录
一、基本属性
app:layout_constraintTop_toBottomOf="@+id/xxx"
这里 top 和 bottom 指当前布局的 top 对齐id为xxx的布局的 bottom
更换其他方位可以达到不同的控制效果,其中有 top、bottom、start、end 分别对应上下左右
二、失效
有的时候发现写了约束布局也没有效果,是其中有一个原因是设置了
match_parent
如果宽度设置了 match_parent 那么左右约束会失效
如果高度设置了 match_parent 那么上下约束会失效
例如:
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_store"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这样设置了约束也没有用,只会在最上面
三、角度定位
app:layout_constraintCircle="@+id/iv_title"
app:layout_constraintCircleAngle="120"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircle 是参照布局
app:layout_constraintCircleAngle 是角度(以钟形在12点方向为基准)
app:layout_constraintCircleRadius 是直径,距离参照
四、Group 整合控件
<android.support.constraint.Group
android:id="@+id/group_vip"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_60"
android:layout_margin="@dimen/dp_10"
app:layout_constraintTop_toBottomOf="@+id/iv_title"
app:constraint_referenced_ids="iv_vip,tv_vip,tv_vip_state,tv_vip_hot"/>
通过 app:constraint_referenced_ids 整合相关控件,统一控制