原文链接:https://juejin.im/post/5a31ee3af265da43294e0fe1

添加依赖

compile 'com.android.support.constraint:constraint-layout:1.0.2'

创建布局

  1. <?xml version="1.0" encoding="utf-8"?>

  2. <android.support.constraint.ConstraintLayout

  3. xmlns:android="http://schemas.android.com/apk/res/android"

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

  5. android:layout_width="match_parent"

  6. android:layout_height="match_parent"

  7. android:orientation="vertical">

  8. <Button

  9. android:id="@+id/bt_a"

  10. android:layout_width="0dp"

  11. android:layout_height="wrap_content"

  12. android:text="scroller_scroll"

  13. android:textSize="12dp"

  14. app:layout_constraintBottom_toTopOf="@+id/button3"

  15. app:layout_constraintHorizontal_weight="1"

  16. app:layout_constraintLeft_toLeftOf="parent"

  17. app:layout_constraintRight_toLeftOf="@+id/bt_b"/>

  18. <Button

  19. android:id="@+id/bt_b"

  20. android:layout_width="0dp"

  21. android:layout_height="wrap_content"

  22. android:text="scroller_fling"

  23. android:textSize="12dp"

  24. app:layout_constraintBottom_toTopOf="@+id/button3"

  25. app:layout_constraintHorizontal_weight="1"

  26. app:layout_constraintLeft_toRightOf="@+id/bt_a"

  27. app:layout_constraintRight_toLeftOf="@+id/bt_c"/>

  28. <Button

  29. android:id="@+id/bt_c"

  30. android:layout_width="0dp"

  31. android:layout_height="wrap_content"

  32. android:text="over_scroll"

  33. android:textSize="12dp"

  34. app:layout_constraintBottom_toTopOf="@+id/button3"

  35. app:layout_constraintHorizontal_weight="1"

  36. app:layout_constraintLeft_toRightOf="@+id/bt_b"

  37. app:layout_constraintRight_toRightOf="@+id/bt_d"/>

  38. <Button

  39. android:id="@+id/bt_d"

  40. android:layout_width="0dp"

  41. android:layout_height="wrap_content"

  42. android:text="overs_fling"

  43. android:textSize="12dp"

  44. app:layout_constraintBottom_toTopOf="@+id/button3"

  45. app:layout_constraintHorizontal_weight="1"

  46. app:layout_constraintLeft_toRightOf="@+id/bt_c"

  47. app:layout_constraintRight_toRightOf="parent"/>

  48. <Button

  49. android:id="@+id/button3"

  50. android:layout_width="0dp"

  51. android:layout_height="wrap_content"

  52. android:layout_marginEnd="8dp"

  53. android:layout_marginStart="8dp"

  54. android:layout_marginTop="8dp"

  55. android:text="Button"

  56. app:layout_constraintBottom_toBottomOf="parent"

  57. app:layout_constraintEnd_toEndOf="parent"

  58. app:layout_constraintStart_toStartOf="parent"

  59. />

  60. </android.support.constraint.ConstraintLayout>

  61. 复制代码

需要了解的地方

  1. 宽度为0dp android:layout_width="0dp"
  2. 需要准确指定左右的约束 app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toLeftOf="@+id/bt_b"//使用@id 编译不通过,使用@+id就可以了
  3. 指定权重 app:layout_constraintHorizontal_weight="1"
  4. 约束也可以为parent app:layout_constraintBottom_toBottomOf="parent"

转载于:https://juejin.im/post/5a31ee3af265da43294e0fe1

ConstraintLayout 平分布局相关推荐

  1. 两个LinearLayout或者ConstraintLayout平分布局

    两个LinearLayout平分布局如图所示: 代码如下,有需要的可以直接复制粘贴到activity_main.xml,之后可以在布局上增加自己想要的控件 <?xml version=" ...

  2. Android ConstraintLayout约束布局的使用

    前言:回廊一寸相思地,落月成孤,背灯和月花阴,已是十年踪迹十年心.                                           -- 虞美人 一.概述 AndroidStudi ...

  3. 【约束布局】ConstraintLayout 约束布局 ( 简介 | 引入依赖 | 基本操作 | 垂直定位约束 | 角度定位约束 | 基线约束 )

    文章目录 一. ConstraintLayout 简介 1. 引入 约束 布局 ( 1 ) 约束性布局 作用 和 简介 2. 约束 简介 ( 1 ) 约束个数要求 ( 2 ) 约束设置 与 显示位置 ...

  4. Android入门教程:ConstraintLayout约束布局

    原文首发自掘金芦苇APP团队,转载到自己小号上再发一遍~ 翻译By Leelion6.关于 ConstraintLayout 的文章其实已经不少了,不过看到这篇文章写的很有趣,以及在翻译的过程中,感受 ...

  5. 约束布局ConstraintLayout加快布局速度

    Android Studio2.2更新布局设计器,同时,引人了约束布局ConstraintLayout. 简单来说,可以把它看做是相对布局的升级版本,但是区别与相对布局更加强调约束.何为约束,即控件之 ...

  6. 哲♂学三幻神带你学习ConstraintLayout(约束布局)

    一句话概括本文: 本文详细讲述了一波 ConstraintLayout约束布局 的用法,应该涵盖了该布局 所有的用法,有遗漏的欢迎评论区提出- 引言 其实这篇文章呢,是很久之前写的了,不过没发到掘金上 ...

  7. 【Android】ConstraintLayout约束布局最全解析

    ConstraintLayout约束布局最全解析 一.ConstraintLayout概述 二.ConstraintLayout基础篇 2.1 基础操作 2.2 控件间添加约束 2.3 约束布局xml ...

  8. Android ConstraintLayout约束布局的理解与使用

    一.什么是约束布局(ConstraintLayout) ConstraintLayout 是一个使用"相对定位"灵活地确定微件的位置和大小的一个布局,在 2016 年 Google ...

  9. layout布局_Android ConstraintLayout 降低布局层次,布局优化首选

    目录 1. 介绍 2. ConstraintLayout的优点 3. ConstraintLayout使用方法 3.1 Relative positioning(相对定位) 3.2 Margins(边 ...

最新文章

  1. 用sqlSessionFactoryBeanName而不用sqlSessionFactory的原因
  2. [转贴]非技术:在广州天河北被抢全记录(入面D广州话真系厉害,不懂粤语者别看,会吐血)...
  3. 演练 课程导航 1002 html
  4. Django(九)admin相关知识
  5. Rabbtmq Confirm 确认消息
  6. dart map 转list_Dart 集合类型List Set Map循环forEach map where any every
  7. 开课吧Java面试题:虚引用与软引用和弱引用的区别
  8. Linux shell脚本详解及实战(五)——shell脚本函数
  9. 杀软自己做 编写autorun病毒免疫工具
  10. GBS国标经纬度转高德经纬度
  11. 集成学习—多算法融合
  12. 【洛谷】P3537 [POI2012]SZA-Cloakroom
  13. Android应用源码基于安卓的个人隐私监控项目
  14. 记录 | KMS工具激活Office报错 Error Code: 0x80080005
  15. webpack打包时提示:The following entrypoint(s) combined asset size exceeds the recommended limit
  16. 2023最新苹果CMS10仿电影先生网站自适应源码/UI简约大气极速加载
  17. 《Multi-Scale Residual Learning-using a Cycle Spinning CNN for Single Image De-Raining》
  18. 实景三维可视化管理平台助力提升景区运营管理水平
  19. 大型数据中心互联(T级光传输方案)
  20. 微博视频处理系统的云原生之路

热门文章

  1. google的glog日志管理
  2. vue事件修饰符,六次实操带你快速了解与应用~
  3. matlab spwm变频调速开环系统电路仿真图,SPWM变频调速系统的原理及仿真模块的建立...
  4. 清科创业IPO:倪正东和他的投资帝国
  5. 鸿蒙os2.0电脑版,鸿蒙os2.0系统正式版下载安装-鸿蒙os2.0系统(华为升级)官方最新版下载-战地2中文网...
  6. goalng 输入账号密码
  7. Mac设置subl启动sublime text
  8. iOS上架流程详细版本
  9. iOS上架详细通关教程
  10. Tomcat构建企业级高负载WEB服务器