Android 开发 ConstraintLayout详解
依赖
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详解的更多相关文章
- Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)
本博前面的文章介绍了Android开发环境的搭建和模拟器的常用操作.本次,将以Android Sample中经典的SoftKeyboard项目为例,详细解析Android上一个小型项目的开发过程和注意 ...
- Android开发——AsyncTask详解
android提供AsynvTask,目的是为了不阻塞主线程(UI线程),且UI的更新只能在主线程中完成,因此异步处理是不可避免的. Android为了降低开发难度,提供了AsyncTask.Asyn ...
- Android开发 Context详解与类型 转载
转载地址:https://blog.csdn.net/guolin_blog/article/details/47028975 个人总结: Context分为 activity : activity其 ...
- Android开发之详解五大布局
http://bbs.chinaunix.net/thread-3654213-1-1.html 为了适应各式各样的界面风格,Android系统提供了5种布局,这5种布局分别是: LinearLayo ...
- Android 开发 HandlerThread详解 转载
转载请注明出处:http://blog.csdn.net/vnanyesheshou/article/details/75073307 对于Handler不太懂的可以参考我的这两篇文章: Androi ...
- Android开发 StateListDrawable详解
前言 StateListDrawable是与xml中的selector属性对应代码实现类,它需要配合GradientDrawable的使用,如果你还不了解GradientDrawable可以参考我的另 ...
- Android开发 GradientDrawable详解
前言 GradientDrawable类似与Xml布局里的shape,常用在一些自己封装的对话框控件的背景或者其他View中,优势是不需要你在带着xml布局文件一起封包.. 画线 GradientDr ...
- Android开发 layer-list详解
参考:https://blog.csdn.net/speverriver/article/details/80925686 挖坑,以后填坑
- Android开发 LevelListDrawable详解
前言 此篇博客正在施工中... 作者其实就是想挖个坑备忘一下... 十分抱歉, 可以参考https://www.jianshu.com/p/f9ec65241b6b
随机推荐
- python rabbitMQ 发送端和接收端广播模式。
消费者模型: import pika,time consumer = pika.BlockingConnection\ (pika.ConnectionParameters('localhost')) ...
- Java入门练习之四则运算
Java入门练习之四则运算 项目目的 制作一个Java控制台程序,让他可以随机生成四则运算,并针对用户的输入判断对错. 项目分析 该项目本质上是一个四则运算出题器,可以创建一个Question类,其中 ...
- 网页真机调试之Browsersync简介
以前的调试方式 修改完项目文件(html.js.css等)后保存,在浏览器刷新页面查看修改后的效果 本地开启一个 tomcat 服务,修改文件后保存刷新页面,移动端或其他 pc 则需要输入 ip + ...
- ansible常用模块入门
常用模块有以下几个 command copy shell crond yum service setup 1.command模块 ansible george -m command -a " ...
- ubuntu升级显卡驱动
2.驱动安装 参考:http://blog.csdn.net/Zafir_410/article/details/73188228 2.1 卸掉已安装的驱动 1 sudo apt-get purge ...
- Spark配置参数详解
以下是整理的Spark中的一些配置参数,官方文档请参考Spark Configuration. Spark提供三个位置用来配置系统: Spark属性:控制大部分的应用程序参数,可以用SparkConf ...
- 收藏品:MP3播放器
大三下学期的时候,有一段生活激情似火. 那时候,我在外边接了项目,把宿舍的哥们儿都组织了起来,一起开发赚钱.我们在小区里租了房子,又多借了一台电脑,哥几个轮流上阵写代码.准备考研的兄弟也帮手做饭,我和 ...
- Spring配置从配置文件读取属性值
spring将properties文件读取后在配置文件中直接将对象的配置信息填充到bean中的变量里. 原本使用PropertyPlaceholderConfigurer类进行文件信息配置.Prope ...
- Tree命令使用
Tree命令使用 格式:tree + 参数 tree命令行参数: -a 显示所有文件和目录. -A 使用ASNI绘图字符显示树状图而非以ASCII字符组合. -C 在文件和目录清单加上色彩,便于区分各 ...
- C#中基于GDI+(Graphics)图像处理系列
https://blog.csdn.net/lhtzbj12/article/details/54024821
