Android ConstraintLayout 约束布局,赶紧学习一下

<android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

属性

相对位置
  • layout_constraintLeft_toLeftOf

  • layout_constraintLeft_toRightOf

  • layout_constraintRight_toLeftOf

  • layout_constraintRight_toRightOf

  • layout_constraintTop_toTopOf

  • layout_constraintTop_toBottomOf

  • layout_constraintBottom_toTopOf

  • layout_constraintBottom_toBottomOf

  • layout_constraintBaseline_toBaselineOf

  • layout_constraintStart_toEndOf

  • layout_constraintStart_toStartOf

  • layout_constraintEnd_toStartOf

  • layout_constraintEnd_toEndOf

边距
  • android:layout_marginStart

  • android:layout_marginEnd

  • android:layout_marginLeft

  • android:layout_marginTop

  • android:layout_marginRight

  • android:layout_marginBottom

被依赖空间GONE之后生效的边距:

- layout_goneMarginStart

- layout_goneMarginEnd

- layout_goneMarginLeft

- layout_goneMarginTop

- layout_goneMarginRight

- layout_goneMarginBottom

水平居中

app:layout_constraintLeft_toRightOf=“parent”

app:layout_constraintRight_toLeftOf="parent

垂直居中

app:layout_constraintTop_toBottompOf=“parent”

app:layout_constraintBottom_toTopOf=“parent”

例子:水平垂直居中:

<?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:layout_width=“match_parent”

android:layout_height=“match_parent”>

<Button

android:id=“@+id/btnA”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“A”

app:layout_constraintBottom_toTopOf=“parent”

app:layout_constraintLeft_toRightOf=“parent”

app:layout_constraintRight_toLeftOf=“parent”

app:layout_constraintTop_toBottomOf=“parent” />

</android.support.constraint.ConstraintLayout>

效果图:

这里写图片描述

偏移

layout_constraintHorizontal_bias // 水平偏移(0-1)

layout_constraintVertical_bias // 垂直偏移(0-1)

例子:按钮B水平偏移50%,相当于居中

<Button

android:id=“@+id/btnB”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“B”

app:layout_constraintHorizontal_bias=“0.5”

app:layout_constraintLeft_toRightOf=“parent”

app:layout_constraintRight_toLeftOf=“parent” />

效果图:

这里写图片描述

可见性

与其他Layout的区别:

-当控件设为GONE时,被认为尺寸为0。可以理解为布局上的一个点。

-若GONE的控件对其它控件有约束,则约束保留并生效,但所有的边距(margin)会清零。

尺寸
MATH_CONSTRAINT
  • layout_constraintWidth_min和layout_constraintHeight_min:设置最小值

  • layout_constraintWidth_max和layout_constraintHeight_max:设置最大值

  • layout_constraintWidth_percent和layout_constraintHeight_percent:

设置控件相对于父容器的百分比大小(1.1.0开始支持)。使用之前需要先设置为百分比模式,然后设置设置宽高值为0~1之间。

设置为百分比模式的属性:

app:layout_constraintWidth_default=“percent”

app:layout_constraintHeight_default=“percent”

强制约束

当一个控件设为wrap_content时,再添加约束尺寸是不起效果的。如需生效,需要设置如下属性为true:

app:layout_constrainedWidth=”true|false”

app:layout_constrainedHeight=”true|false”

比例

控件可以定义两个尺寸之间的比例,目前支持宽高比。前提条件是至少有一个尺寸设置为0dp,然后通过layout_constraintDimentionRatio属性设置宽高比。设置方式有以下几种:

  • 直接设置一个float值,表示宽高比

  • 以” width:height”形式设置

  • 通过设置前缀W或H,指定一边相对于另一边的尺寸,如”H, 16:9”,高比宽为16:9

如果宽高都设置为0dp,也可以用ratio设置。这种情况下控件会在满足比例约束的条件下,尽可能填满父布局。

例子:按钮E宽度设为0dp,高度wrap_content,宽高比设为2:1;按钮F高度设为0dp,宽度设为wrap_content,宽高比设为1:3

<Button

android:id=“@+id/btnE”

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:text=“E”

app:layout_constraintDimensionRatio=“2:1”

app:layout_constraintLeft_toLeftOf=“parent”

app:layout_constraintTop_toBottomOf=“@id/btnB” />

<Button

android:id=“@+id/btnF”

android:layout_width=“wrap_content”

android:layout_height=“0dp”

android:text=“F”

app:layout_constraintDimensionRatio=“1:3”

app:layout_constraintTop_toBottomOf=“@id/btnE” />

效果图:

这里写图片描述

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

Android开发除了flutter还有什么是必须掌握的吗?

相信大多数从事Android开发的朋友们越来越发现,找工作越来越难了,面试的要求越来越高了

除了基础扎实的java知识,数据结构算法,设计模式还要求会底层源码,NDK技术,性能调优,还有会些小程序和跨平台,比如说flutter,以思维脑图的方式展示在下图;

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

/H4lCoPEF.jpg" />

Android开发除了flutter还有什么是必须掌握的吗?

相信大多数从事Android开发的朋友们越来越发现,找工作越来越难了,面试的要求越来越高了

除了基础扎实的java知识,数据结构算法,设计模式还要求会底层源码,NDK技术,性能调优,还有会些小程序和跨平台,比如说flutter,以思维脑图的方式展示在下图;

[外链图片转存中…(img-vA8TsojF-1712336062025)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值