前面的文章

ConstraintLayout 介绍 (一)

ConstraintLayout约束属性 (二)

ConstraintLayout 宽高比和偏移量比(三)

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(五)的更多相关文章

  1. Android ConstraintLayout详解(from jianshu)

    Android ConstraintLayout详解 https://www.jianshu.com/p/a8b49ff64cd3 1. 概述     在本篇文章中,你会学习到有关Constraint ...

  2. Android系统--输入系统(五)输入系统框架

    Android系统--输入系统(五)输入系统框架 1. Android设备使用场景: 假设一个Android平板,APP功能.系统功能(开机关机.调节音量).外接设备功能(键盘.触摸屏.USB外接键盘 ...

  3. Android开发艺术探索第五章——理解RemoteViews

    Android开发艺术探索第五章--理解RemoteViews 这门课的重心在于RemoteViews,RemoteViews可以理解为一种远程的View,其实他和远程的Service是一样的,Rem ...

  4. Android源码浅析(五)——关于定制系统,如何给你的Android应用系统签名

    Android源码浅析(五)--关于定制系统,如何给你的Android应用系统签名 今天来点简单的我相信很多定制系统的同学都会有一些特定功能的需求,比如 修改系统时间 静默安装 执行某shell命令 ...

  5. Android BLE与终端通信(五)——Google API BLE4.0低功耗蓝牙文档解读之案例初探

    Android BLE与终端通信(五)--Google API BLE4.0低功耗蓝牙文档解读之案例初探 算下来很久没有写BLE的博文了,上家的技术都快忘记了,所以赶紧读了一遍Google的API顺便 ...

  6. Android高级控件(五)——如何打造一个企业级应用对话列表,以QQ,微信为例

    Android高级控件(五)--如何打造一个企业级应用对话列表,以QQ,微信为例 看标题这么高大上,实际上,还是运用我么拿到listview去扩展,我们讲什么呢,就是研究一下QQ,微信的这种对话列表, ...

  7. Android群英传笔记——第五章:Android Scroll分析

    Android群英传笔记--第五章:Android Scroll分析 滑动事件算是Android比较常用的效果了,而且滑动事件他本身也是有许多的知识点,今天,我们就一起来耍耍Scroll吧 一.滑动效 ...

  8. Android实训案例(五)——四大组件之一ContentProvider的使用,通讯录的实现以及ListView的优化

    Android实训案例(五)--四大组件之一ContentProvider的使用,通讯录的实现 Android四大组件是啥这里就不用多说了,看图吧,他们之间通过intent通讯 我们后续也会一一的为大 ...

  9. Android ConstraintLayout约束控件链接整理

    Android新特性介绍,ConstraintLayout完全解析 探索Android ConstraintLayout布局 了解使用Android ConstraintLayout

随机推荐

  1. shell中使用echo输出时如何指定颜色

    答: 请看下图:

  2. php高级开发参考地址

    高级开发 : http://www.cnblogs.com/bananaplan/p/The-Right-Way-For-PHPer.html

  3. 微生物增殖|2012年蓝桥杯B组题解析第一题-fishers

    (3')微生物增殖 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1 ...

  4. HDU 4632 Palindrome subsequence & FJUT3681 回文子序列种类数(回文子序列个数/回文子序列种数 容斥 + 区间DP)题解

    题意1:问你一个串有几个不连续子序列(相同字母不同位置视为两个) 题意2:问你一个串有几种不连续子序列(相同字母不同位置视为一个,空串视为一个子序列) 思路1:由容斥可知当两个边界字母相同时 dp[i ...

  5. 【做题】agc006C - Rabbit Exercise——模型转换

    原文链接https://www.cnblogs.com/cly-none/p/9745177.html 题意:数轴上有\(n\)个点,从\(1\)到\(n\)编号.有\(m\)个操作,每次操作给出一个 ...

  6. PTA 7-2 符号配对(20 分)

    7-2 符号配对(20 分) 请编写程序检查C语言源程序中下列符号是否配对:/*与*/.(与).[与].{与}. 输入格式: 输入为一个C语言源程序.当读到某一行中只有一个句点.和一个回车的时候,标志 ...

  7. linux 进阶命令笔记(12月26日)

    1. df 指令 作用:查看磁盘空间 用法: #df -h       -h 表示以可读性较高的形式展示大小   2.free 指令 作用:查看内存使用情况 语法:#free -m       -m表 ...

  8. HTML的Doctype

    1. <!DOCTYPE> 声明位于文档中的最前面,处于 <html> 标签之前.告知浏览器的解析器,用什么文档类型 规范来解析这个文档. 2. 严格模式的排版和 JS 运作模 ...

  9. HttpDns原理

    什么是 DNS DNS(Domain Name System,域名系统),DNS 服务用于在网络请求时,将域名转为 IP 地址.能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的 IP 数 ...

  10. 33 Python 详解命令解析 - argparse--更加详细--转载

    https://blog.csdn.net/lis_12/article/details/54618868 Python 详解命令行解析 - argparse Python 详解命令行解析 - arg ...