ConstraintLayout 简单使用——开发记录

原因:
接受新项目,大部分布局使用的是ConstraintLayout ,但是自己没有太多的接触;这篇博客的目的是记录ConstrainLayout大概使用方式。
介绍
Constraintlayout 是Android Studio 2.2中主要的新增功能之一,它和传统编写方式不同,ConstrainLayout非常适合使用可视化的方式来编写界面。但是并不太适合使用xml的方式进行编写,当然,可视化操作的背后仍然还是使用的xml代码来实现的,只不过这些代码是由AndroidStrudio根据我们的操作自动生成的。

优点
有效的解决布局嵌套过多的问题,我们平时编写界面,复杂的布局总是会伴随着多层级的嵌套,而嵌套太多,程序的性能也就越差。ConstrainLayout则是使用约束的方式来指定各个控件的位置和关系的。它有点类似RelativeLayout, 但是远比RelativeLayout更强大。

开始

前提:确保自己的项目是运行在 Android Studio 是在2.2版本之上的。

第一步:导包
dependencies {
compile ‘com.android.support.constraint:constraint-layout:1.0.0-beta4’
}

第二步:新建xml文件

<android.support.constraint.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"
    android:background="@color/color_7">

使用

参考郭霖大神的 ContraintLayout

参考实战篇

猜你喜欢

转载自blog.csdn.net/qq_30974087/article/details/83272838