ConstraintLayout 使用可视化的方式来编写Android应用程序的界面。

Module中默认的布局就是ConstraintLayout。如下所示:

xmlns:android=”http://schemas.android.com/apk/res/android”

xmlns:app=”http://schemas.android.com/apk/res-auto”

xmlns:tools=”http://schemas.android.com/tools”

android:layout_width=”match_parent”

android:layout_height=”match_parent”

tools:context=”com.constraintlayout.app.Main2Activity”>

在使用ConstraintLayout的布局方案,需要在build.gradle引入支持库:

dependencies{

compile’com.android.support.constraint:constraint-layout:1.0.1′}

具体使用:

http://blog.csdn.net/guolin_blog/article/details/53122387(郭神的博客)

http://www.jianshu.com/p/a8b49ff64cd3

常用方法总结

layout_constraintTop_toTopOf// 将所需视图的顶部与另一个视图的顶部对齐。

layout_constraintTop_toBottomOf// 将所需视图的顶部与另一个视图的底部对齐。

layout_constraintBottom_toTopOf// 将所需视图的底部与另一个视图的顶部对齐。

layout_constraintBottom_toBottomOf// 将所需视图的底部与另一个视图的底部对齐。

layout_constraintLeft_toTopOf// 将所需视图的左侧与另一个视图的顶部对齐。

layout_constraintLeft_toBottomOf// 将所需视图的左侧与另一个视图的底部对齐。

layout_constraintLeft_toLeftOf// 将所需视图的左边与另一个视图的左边对齐。

layout_constraintLeft_toRightOf// 将所需视图的左边与另一个视图的右边对齐。

layout_constraintRight_toTopOf// 将所需视图的右对齐到另一个视图的顶部。

layout_constraintRight_toBottomOf// 将所需视图的右对齐到另一个的底部。

layout_constraintRight_toLeftOf// 将所需视图的右边与另一个视图的左边对齐。

layout_constraintRight_toRightOf// 将所需视图的右边与另一个视图的右边对齐。

表示wrap content

表示固定值,也就是给控件指定了一个固定的长度或者宽度值。

表示any size,它有点类似于match parent,但和match parent并不一样,是属于ConstraintLayout中特有的一种大小控制方式,any size就是用于在ConstraintLayout中顶替match parent.

    原文作者:Vegetable蔬菜
    原文地址: https://www.jianshu.com/p/bfd993872848
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞