android -------- ConstraintLayout Group和goneMargin(五)
前面的文章
ConstraintLayout Guideline和Barrier(四)
此博文主要讲解: Group和goneMargin
1:Group
在开发中,有时候需要同时隐藏或者显示多个控件,用Group就可以很好的实现,是一个辅助类,不会绘制到屏幕上,也不会展现给用户。
通过属性app:constraint_referenced_ids
将一些 View 组成组进行集体操作,最常见的操作是setVisibility。
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!--android.support.constraint.Group(群组)
--> <TextView
android:id="@+id/tv1"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="@string/app_name"
android:background="@color/colorAccent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
android:layout_marginTop="15dp"
app:layout_constraintTop_toTopOf="parent"
/> <TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:layout_marginTop="15dp"
app:layout_constraintStart_toEndOf="@+id/tv1"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="15dp"
/> <android.support.constraint.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="tv1,tv2"
android:visibility="visible"
/> </android.support.constraint.ConstraintLayout>
将 android:visibility="gone" 则两个布局都隐藏掉了
2:goneMargin
当前View与另一个View绑定后,另一个View的属性设置为了Gone,则以下属性会生效
layout_goneMarginStart
layout_goneMarginEnd
layout_goneMarginLeft
layout_goneMarginTop
layout_goneMarginRight
layout_goneMarginBottom
代码:
<?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"> <!-- app:layout_goneMarginLeft="25dp"
tv1 设置了android:visibility="gone" 才生效(当前View与另一个View绑定后,
另一个View的属性设置为了Gone,才会生效)
--> <TextView
android:id="@+id/tv1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f5ec7e"
android:gravity="center"
android:text="Hello World!"
app:layout_constraintLeft_toLeftOf="parent"
android:visibility="gone"
/> <TextView
android:id="@+id/tv2"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#fa6e61"
android:gravity="center"
android:text="Hello World!"
app:layout_constraintLeft_toRightOf="@+id/tv1"
android:layout_marginLeft="15dp"
app:layout_goneMarginLeft="55dp"
/> </android.support.constraint.ConstraintLayout>
Group和goneMargin 这两个属性很简单,使用也方便
android -------- ConstraintLayout Group和goneMargin(五)的更多相关文章
- Android ConstraintLayout详解(from jianshu)
Android ConstraintLayout详解 https://www.jianshu.com/p/a8b49ff64cd3 1. 概述 在本篇文章中,你会学习到有关Constraint ...
- Android系统--输入系统(五)输入系统框架
Android系统--输入系统(五)输入系统框架 1. Android设备使用场景: 假设一个Android平板,APP功能.系统功能(开机关机.调节音量).外接设备功能(键盘.触摸屏.USB外接键盘 ...
- Android开发艺术探索第五章——理解RemoteViews
Android开发艺术探索第五章--理解RemoteViews 这门课的重心在于RemoteViews,RemoteViews可以理解为一种远程的View,其实他和远程的Service是一样的,Rem ...
- Android源码浅析(五)——关于定制系统,如何给你的Android应用系统签名
Android源码浅析(五)--关于定制系统,如何给你的Android应用系统签名 今天来点简单的我相信很多定制系统的同学都会有一些特定功能的需求,比如 修改系统时间 静默安装 执行某shell命令 ...
- Android BLE与终端通信(五)——Google API BLE4.0低功耗蓝牙文档解读之案例初探
Android BLE与终端通信(五)--Google API BLE4.0低功耗蓝牙文档解读之案例初探 算下来很久没有写BLE的博文了,上家的技术都快忘记了,所以赶紧读了一遍Google的API顺便 ...
- Android高级控件(五)——如何打造一个企业级应用对话列表,以QQ,微信为例
Android高级控件(五)--如何打造一个企业级应用对话列表,以QQ,微信为例 看标题这么高大上,实际上,还是运用我么拿到listview去扩展,我们讲什么呢,就是研究一下QQ,微信的这种对话列表, ...
- Android群英传笔记——第五章:Android Scroll分析
Android群英传笔记--第五章:Android Scroll分析 滑动事件算是Android比较常用的效果了,而且滑动事件他本身也是有许多的知识点,今天,我们就一起来耍耍Scroll吧 一.滑动效 ...
- Android实训案例(五)——四大组件之一ContentProvider的使用,通讯录的实现以及ListView的优化
Android实训案例(五)--四大组件之一ContentProvider的使用,通讯录的实现 Android四大组件是啥这里就不用多说了,看图吧,他们之间通过intent通讯 我们后续也会一一的为大 ...
- Android ConstraintLayout约束控件链接整理
Android新特性介绍,ConstraintLayout完全解析 探索Android ConstraintLayout布局 了解使用Android ConstraintLayout
随机推荐
- topcoder srm 530 div1
problem1 link 对于每个还未切掉的‘X’用cutter作用一次.从左上角到右下角,依次判断即可. problem2 link 首先,如果一个顶点不能从0到达或者不能到达节点$n-1$,那么 ...
- LuoguP2161 [SHOI2009]会场预约
题目地址 题目链接 题解 用fhqtreap对区间进行维护. 可以注意到的是,对于当前存在的预约,他们一定是升序排列的(有重叠的都被删了). 那么就可以用按照位置分裂的fhqtreap搞了(预约无论按 ...
- nginx的高可用集群
1,阿里云:SLB 2, 硬件负载均衡器(如:F5,RedWare ) 3,软件实现高可用或负载均衡.keepalived
- (转载)一张表搞清楚西门子S7系列标准DB块与优化DB块
在TIA Portal中为S7-1200/S7-1500 CPU 添加一个 DB 块时,其缺省属性为优化的 DB ,优化的 DB 块与标准的 DB 块整体对比如下表所示: 项 标准 DB 优化 DB ...
- POJ 2718 Smallest Difference(最小差)
Smallest Difference(最小差) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given a numb ...
- js url参数和对象互转
function param(a) { var s = [], rbracket = /\[\]$/, isArray = function(obj) { return Object.prototyp ...
- 17. --cover-- 覆盖掩盖 (词19)
- SAP 供应商/客户的冻结及其删除操作
SAP 供应商/客户的冻结及其删除操作 在SAP中,有所谓的财务供应商(Tcode:FK01)和后勤供应商(Tcode:XK01),供应商和客户主数据包括一般数据/公司代码数据/采购组织|销售范围三方 ...
- C#——LINQ语句
委托: //delegate 返回值 委托名(参数); //委托不能在方法中定义 ////实例化委托,并赋值 //委托名 实例名 = new 委托名(函数名).lambda表达式; //使用委托实例, ...
- 删除node_modules文件
删除node_modules文件夹报错:路径太长,无法删除. npm install rimraf -g rimraf node_modules