依赖

    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'

app:layout_constraintHorizontal_chainStyle

间隔类型

app:layout_constraintDimensionRatio

设置控件宽高百分百

<Button android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

app:layout_constraintHorizontal_bias 与 app:layout_constraintVertical_bias

设置 横向 和 竖向 控件位置百分百

<ImageView
android:id="@+id/up_down_image"
android:src="@mipmap/ic_triangle_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_bias="0.55"
app:layout_constraintTop_toTopOf="@id/select_class"
app:layout_constraintBottom_toBottomOf="@id/select_class"
app:layout_constraintLeft_toRightOf="@id/bg"
app:layout_constraintRight_toLeftOf="@id/bg"/>

app:layout_constraintWidth_percent 与 app:layout_constraintHeight_percent

设置控件宽度与高度在父布局宽度或者高度占的的百分比大小

<TextView
android:id="@+id/text_noon"
android:text="demo"
android:textSize="@dimen/font_size_14"
android:textColor="@color/fontBlack3"
android:background="@color/colorGreen"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
app:layout_constraintHorizontal_bias="0.90"
app:layout_constraintWidth_percent="0.20"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>

app:layout_constrainedWidth 与 app:layout_constrainedHeight

在一些TextView或者Button控件,控件大小可能会跟随内容变化,这个时候设置2个属性就可以分别在宽度和高度是强制约束给定的大小,让控件宽度或者高度不会超过给予的约束范围

constraintlayout.widget.Barrier

约束辅助线

用于当有2个View 都有可能在隐藏状态,但是另外一个View需要根据这2个View改变位置.这个时候layout_constraintRight_toLeftOf这个属性你会发现你只有一个,但是需要判断2个View.所以这个约束辅助线作用就出来了,它的constraint_referenced_ids这个属性可以添加多个View并且根据这些View改变位置.

<androidx.constraintlayout.widget.Barrier
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left"
app:constraint_referenced_ids="up_down_image,text_content"
app:layout_constraintTop_toTopOf="@id/bg"
app:layout_constraintBottom_toBottomOf="@id/bg"
app:layout_constraintRight_toLeftOf="@id/up_down_image"/>

constraintlayout.widget.Guideline

辅助线

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.04"/>

constraintlayout.widget.Group

将若干个控件组合在一起,主要是使用android:visibility="gone"属性一次性隐藏多个控件

<androidx.constraintlayout.widget.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="line,whether,opinion"
app:layout_constraintTop_toBottomOf="@id/name"
app:layout_constraintLeft_toLeftOf="parent"/>

app:layout_constraintCircle

圆形定位,让B控件以A控件为圆形围绕在指定角度文字

<Button android:id="@+id/buttonA" ... />
<Button android:id="@+id/buttonB" ...
//引用的控件ID
app:layout_constraintCircle="@+id/buttonA"
//圆半径
app:layout_constraintCircleRadius="100dp"
//偏移圆角度 水平右方向为0逆时针方向旋转
app:layout_constraintCircleAngle="45" />

Space

<Space
android:layout_width="0dp"
android:layout_height="20dp"
app:layout_constraintTop_toBottomOf="@id/opinion"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

Android 开发 ConstraintLayout详解的更多相关文章

  1. Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)

    本博前面的文章介绍了Android开发环境的搭建和模拟器的常用操作.本次,将以Android Sample中经典的SoftKeyboard项目为例,详细解析Android上一个小型项目的开发过程和注意 ...

  2. Android开发——AsyncTask详解

    android提供AsynvTask,目的是为了不阻塞主线程(UI线程),且UI的更新只能在主线程中完成,因此异步处理是不可避免的. Android为了降低开发难度,提供了AsyncTask.Asyn ...

  3. Android开发 Context详解与类型 转载

    转载地址:https://blog.csdn.net/guolin_blog/article/details/47028975 个人总结: Context分为 activity : activity其 ...

  4. Android开发之详解五大布局

    http://bbs.chinaunix.net/thread-3654213-1-1.html 为了适应各式各样的界面风格,Android系统提供了5种布局,这5种布局分别是: LinearLayo ...

  5. Android 开发 HandlerThread详解 转载

    转载请注明出处:http://blog.csdn.net/vnanyesheshou/article/details/75073307 对于Handler不太懂的可以参考我的这两篇文章: Androi ...

  6. Android开发 StateListDrawable详解

    前言 StateListDrawable是与xml中的selector属性对应代码实现类,它需要配合GradientDrawable的使用,如果你还不了解GradientDrawable可以参考我的另 ...

  7. Android开发 GradientDrawable详解

    前言 GradientDrawable类似与Xml布局里的shape,常用在一些自己封装的对话框控件的背景或者其他View中,优势是不需要你在带着xml布局文件一起封包.. 画线 GradientDr ...

  8. Android开发 layer-list详解

    参考:https://blog.csdn.net/speverriver/article/details/80925686 挖坑,以后填坑

  9. Android开发 LevelListDrawable详解

    前言 此篇博客正在施工中... 作者其实就是想挖个坑备忘一下... 十分抱歉, 可以参考https://www.jianshu.com/p/f9ec65241b6b

随机推荐

  1. 个人 git-hub使用方法

    注册码云 安装git hub git init here         创建本地仓库(repository),将会在文件夹下创建一个 .git 文件夹,.git 文件夹里存储了所有的版本信息.标记等 ...

  2. 在ubuntu服务器上安装tomcat 9

    前提条件: 确保ubuntu服务器上 已经安装 java 8 或更高版本,安装java8可以参考我的另一篇博文 通过 ppa 在ubuntu server 上安装java 8 java -versio ...

  3. sklearn pipeline

    sklearn.pipeline pipeline的目的将许多算法模型串联起来,比如将特征提取.归一化.分类组织在一起形成一个典型的机器学习问题工作流. 优点: 1.直接调用fit和predict方法 ...

  4. MongoDB连接

    1. import pymongo client = pymongo.MongoClient(host='localhost',port=27017) 2. client=MongoClient('m ...

  5. java基础(一):我对java的三个环境变量的简单理解和配置

    首先说说java的三个环境变量:java_home,classpath,path java_home:jdk的安装路径[你一层一层点开安装路径,直到当前目录有一个bin目录,然后在地址栏里面右键单击复 ...

  6. 迭代器使用【阿里JAVA开发手册】

    调用迭代器的remove的方法(它的方法实现是:调用ArrayList的remove(index)方法 ) 然后游标cursor相应的进行减1操作

  7. C++——volatile关键字的学习

    首先声明一点,本文是关于volatile关键字的学习,学习内容主要是来自一些大牛的网络博客. 一篇是何登成先生的C/C++ Volatile关键词深度剖析(http://hedengcheng.com ...

  8. ASP.NET: Cookie会话丢失,Session超时配置

    问题描述: asp.net应用中web.config的SessionState节点:原先是 <sessionState mode="InProc" timeout=" ...

  9. Proxifier代理工具简介和下载

    Proxifier 是一款功能非常强大的socks5客户端,可以让不支持通过代理服务器工作的网络程序能通过HTTPS或SOCKS代理或代理链.支持64位系统,支持Xp,Vista,Win7,支持soc ...

  10. Difference between ulimit, lsof, cat /proc/sys/fs/file-max

    https://unix.stackexchange.com/questions/476351/difference-between-ulimit-lsof-cat-proc-sys-fs-file- ...