ConstraintLayout的基本使用
来源:互联网 发布:淘宝钻石展位图片尺寸 编辑:程序博客网 时间:2024/06/05 11:50
一、概述:
ConstraintLayout允许您使用平面视图层次结构(无嵌套视图组)创建大而复杂的布局。 它与RelativeLayout类似,所有的视图都是根据兄弟视图和父布局之间的关系来布局的,但是它比RelativeLayout更灵活,并且更易于在Android Studio的布局编辑器中使用。
ConstraintLayout的所有功能都可以直接从布局编辑器的可视化工具中使用,因为布局API和布局编辑器是专门为对方构建的。 所以你可以使用ConstraintLayout完全通过拖放操作来构建你的布局,而不是编辑XML。
二、自己的操作:手写各约束布局属性
1、首先需要引入我们的ConstraintLayout,在build.gradle中加入:(现在创建应用默认加入)
compile 'com.android.support.constraint:constraint-layout:1.0.2'
2、我们使用ConstraintLayout来写
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#11ff0000" > <TextView android:id="@+id/tv1" android:layout_width="140dp" android:layout_height="86dp" android:layout_marginLeft="12dp" android:layout_marginTop="12dp" android:background="#617" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/tv2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="12dp" android:text="就现在经济大环境而言,很不乐观,程序员的日子也很不好过" android:textColor="#000000" android:textSize="16dp" app:layout_constraintLeft_toRightOf="@id/tv1" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="@id/tv1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="12dp" android:text="25分钟前" android:textColor="#333" android:textSize="12dp" app:layout_constraintLeft_toRightOf="@id/tv1" app:layout_constraintBottom_toBottomOf="@id/tv1" /></android.support.constraint.ConstraintLayout>
tv1设置了://父布局的左上角
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tv2设置了:tv2在tv1的右侧,tv2的右侧和父布局对其,tv2和tv1顶部对齐;
app:layout_constraintLeft_toRightOf="@id/tv1",
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv1"
tv3设置了:tv3在tv1的右侧,tv3和tv1底部对其。
app:layout_constraintLeft_toRightOf="@id/tv1"
app:layout_constraintBottom_toBottomOf="@id/tv1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tv2设置了:tv2在tv1的右侧,tv2的右侧和父布局对其,tv2和tv1顶部对齐;
app:layout_constraintLeft_toRightOf="@id/tv1",
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv1"
tv3设置了:tv3在tv1的右侧,tv3和tv1底部对其。
app:layout_constraintLeft_toRightOf="@id/tv1"
app:layout_constraintBottom_toBottomOf="@id/tv1"
与之类似的还有几个属性:
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBaseline_toBaselineOf
总体来说如果嵌套很多层的使用这个替换还是有必要的,就是简单的玩了一下等后面做复杂布局再继续完善吧
三、API 参考文档:
原生态健康品的学习
四、来自大牛的启蒙:
可视化界面学习推荐:郭霖:Android新特性介绍,ConstraintLayout完全解析
手写各约束布局属性:鸿洋:ConstraintLayout 完全解析 快来优化你的布局吧
阅读全文
0 0
- ConstraintLayout的基本使用
- ConstraintLayout布局的基本使用
- ConstraintLayout布局的基本使用
- Android ConstraintLayout的基本使用
- ConstraintLayout的简单使用
- ConstraintLayout 的使用
- ConstraintLayout的使用
- ConstraintLayout的使用介绍
- ConstraintLayout的学习使用
- 新布局节点ConstraintLayout基本使用
- Android ConstraintLayout布局的使用
- ConstraintLayout使用解析并去掉ConstraintLayout的默认布局方式
- ConstraintLayout使用解析并去掉ConstraintLayout的默认布局方式
- 使用ConstraintLayout创建复杂的表单布局
- ConstraintLayout约束布局的概念与使用
- 使用ConstraintLayout构建一个灵活的布局
- 2017/02/10 使用 ConstraintLayout 的总结
- Android新布局ConstraintLayout的使用
- 利用HashMap辅助调整对象结构
- 微信支付:curl出错,错误码:60
- ubuntu 下出现E: Sub-process /usr/bin/dpkg returned an error code
- 关于Hibernate报错 “table” is not mapped
- docker中部署dpdk功能验证
- ConstraintLayout的基本使用
- 如何在Qt中使用自己编译好的so库
- sublime text 3 中 SFTP插件 的 配置
- java 线程池详解及四种线程池用法介绍
- BZOJ 2839: 集合计数 容斥原理 组合数学
- 人脸对齐--Unconstrained Face Alignment without Face Detection
- 【ubantu crontab】crontab 无法保存退出,坑死了
- DB-Engines最新11月数据库排名:MariaDB助力_MySQL流行度超越Oracle
- WPF 用户控件 文本框