1.首先引入对应的包
compile 'com.android.support.constraint:constraint-layout:1.0.2'
2.记录一下对应用的属性
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
# 即文章的baseline对齐
layout_constraintBaseline_toBaselineOf
# 与left,right类似
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf
# margin不需要解释
android:layout_marginStart
android:layout_marginEnd
android:layout_marginLeft
android:layout_marginTop
android:layout_marginRight
android:layout_marginBottom
layout_constraintHorizontal_bias
layout_constraintVertical_bias
layout_constraintHorizontal_chainStyle
layout_constraintVertical_chainStyle
layout_constraintVertical_weight
Guideline
3.贴一下简单的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/banner"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="banner"
android:textColor="@color/white"
android:gravity="center"
app:layout_constraintDimensionRatio="H,16:6"
android:background="@color/balck_333"/>
<TextView
android:id="@+id/image"
android:layout_width="130dp"
android:layout_height="88dp"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/banner"
android:background="@color/red"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/image"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="@string/code_share_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toRightOf="@+id/image"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:text="厉害了我自己!在“gogo”又完成一笔交易!"/>
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:text="订单"
android:textColor="@color/white"
android:gravity="center"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9"
app:layout_constraintHorizontal_bias="0.98"
android:background="@drawable/shape_shopcar_num"/>
<TextView
android:id="@+id/tab1"
android:layout_width="0dp"
android:layout_height="40dp"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tab2"
android:text="tab1"/>
<TextView
android:id="@+id/tab2"
android:layout_width="0dp"
android:layout_height="40dp"
android:gravity="center"
android:background="@color/colorPrimary"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/tab1"
app:layout_constraintRight_toRightOf="@+id/tab3"
android:text="tab2"/>
<TextView
android:id="@+id/tab3"
android:layout_width="0dp"
android:layout_height="40dp"
android:gravity="center"
android:background="@color/colorPrimary"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/tab2"
app:layout_constraintRight_toRightOf="parent"
android:text="tab3"/>
</android.support.constraint.ConstraintLayout>
贴一下效果图
另外其实是可以用拖拽的方式来实现的,具体可以参考郭神,鸿神的文章有具体的介绍:
http://blog.csdn.net/guolin_blog/article/details/53122387
http://blog.csdn.net/lmj623565791/article/details/78011599