前面的文章

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. 用uniGUI做B/S下业务系统的产品原型体验

    从10月份到重庆工作后,一直忙于工作,感兴趣的几个方面的技术都处于暂停. 一个多月来,按照公司要求在做B/S集中式基卫产品的原型,主要是画原型图,开始是用Axure,弄来弄去感觉功能还是弱了些,尤其是 ...

  2. 闪存中的NorFlash、NandFlash及eMMC三者的区别【转】

    本文转载自:https://blog.csdn.net/Blazar/article/details/77843655 快闪存储器(英语:Flash Memory),是一种电子式可清除程序化只读存储器 ...

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

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

  4. Java日期时间(Date/Time)

    获取当前日期和时间 在Java中容易得到当前的日期和时间.可以使用一个简单的Date对象的toString()方法,如下所示打印当前日期和时间: import java.util.Date; publ ...

  5. 操作系统04_IO管理

    输入输出系统 IO系统的层次结构 用户层IO软件 设备独立性软件 设备驱动程序 中断处理程序 对IO设备的控制方式 使用轮询的可编程IO方式 cpu不停地检查设备的状态,以字节为单位,非中断方式,利用 ...

  6. asp.net core mvc 中在C# 代码中写 js 或html 文本

    https://blog.csdn.net/orichisonic/article/details/62046621 使用<text>这个伪元素来强制Razor从编译模式返回到内容模式: ...

  7. (zhuan) Attention in Long Short-Term Memory Recurrent Neural Networks

    Attention in Long Short-Term Memory Recurrent Neural Networks by Jason Brownlee on June 30, 2017 in  ...

  8. 常用linux,DOS命令——持续更新

    cd 文件夹名 进入某个文件夹 cd ../ 退出该级目录进入上一级 cd ../../ 退出该级目录进入上上级 cd ../../demo 退出该级目录进入上上级的目录 d: 回车 进入d盘 ls ...

  9. 移动端开发:使用jQuery Mobile还是Zepto

    原:http://blog.csdn.net/liubinwyzbt/article/details/51446771 jQuery Mobile和Zepto是移动端的js库.jQuery Mobil ...

  10. 1月4日笔记 (vi编辑器)更新...

      vi编辑器,全称是visual interface,可以执行输出.删除.查找.替换等众多的文本操作. vi并不是一个排版程序,不可以对字体.格式.段落等其他的属性进行编排. vi是全屏文本编辑程序 ...