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
随机推荐
- VS2013 Winform程序打包部署 InstallShield2015LimitedEdition
VS2013 Winform程序打包部署 VS2013默认是没有安装打包程序的,需要手动安装,我安装的是 InstallShield2015LimitedEdition. 1.点击解决方案,右键,选择 ...
- 《Java核心技术(卷一)》读书笔记——第六章:内部类
1. 内部类的概念? 类中类 2. 为什么要用内部类? 内部类的方法可以访问外部类的实例域 内部类对外部类的同一个包中的类实现了隐藏 匿名内部类在“想要定义一个回调函数却又不想编写 ...
- vb.net
vb.net 教程: https://www.yiibai.com/vb.net/vb.net_overview.html vb.net 教程 https://www.w3cschool.cn/vb_ ...
- HtmlUnit学习总结
HtmlUnit学习总结 转载 2016年09月13日 15:58:25 标签: htmlunit / 爬虫 7304 本文摘抄其他博客或者技术论坛,自己搜集整理如下: HtmlUnit学习总结 摘要 ...
- 关于定时器setTimeout()方法的实践--巧解bug
_使用开发环境:UAP:_ _框架:JQuery.MX:_ 最近的开发的页面中,有一处需要在提交的 datagrid里启用行编辑,就会发生奇怪的bug,编辑过程中如图所示不移开焦点直接点保存,那么已输 ...
- c#死锁示例代码
void Main() { object obj1 = new object(); object obj2 = new object(); var t1 = new Thread(delegate(o ...
- zabbix安装源
使用zabbix安装源可以避免版本不同的问题,自己根据自己的需求选择对应的版本即可 http://repo.zabbix.com/zabbix/
- Web前端3.0时代,“程序猿”如何“渡劫升仙”
Web前端入行门槛低,很多人在成为前端工程师后很容易进入工作的舒适区,认为该熟悉的业务已熟悉了,然后就是重复用轮子,这样很容易让自己的成长处于原地打转以及低水平重复的状态. 想要不被行业抛弃,就要努力 ...
- 2019软件工程第二次作业(VS2017中对C++的单元测试)
建立工程,分别编写cpp和头文件 cpp文件中的代码如下: #include<iostream> #include"test.h" using namespace st ...
- neo4j通过LOAD CSV导入结点和关系
1.neo4j默认的导入入口是:安装路径/import,所以要将csv文件放在import目录下,像下面这样: 2.导入后中文乱码: 因为neo4j是utf-8的,而CSV默认保存是ANSI的,需要用 ...