前面的文章

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. Python3基础 dict fromkeys 多个键对应相同的值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. vba编程基础1

    在主要的编程语言中, 结构体是用大括号来表示 代码段的 范围 界定的. 但是在一些比较"老的"语言中,由于历史原因, 还是使用的 是: 关键字来进行界定代码 的 结构段, 如vba ...

  3. 【基本知识】Flume基本环境搭建以及原理

    系统:CentOS6.5JDK:1.8.0_144Flume:flume-ng-1.6.0-cdh5.12.0 一.什么是Flume flume 作为 cloudera 开发的实时日志收集系统,受到了 ...

  4. (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  ...

  5. Twitter OAuth

    新浪微博和 Twitter 的 Oauth API 为什么感觉流程不一样 新浪: 开发者引导用户到新浪授权页面, 页面链接中需要带上自己的 apikey : 用户授权后新浪跳转到开发者指定指定的页面, ...

  6. windows service in vs

    用 vs2013 创建 windows service 程序 vs2015开发Windows服务 VS 2010一步步开发windows服务(windows service)

  7. cmd中utf-8编码的问题

    有时候我们需要使用cmd显示某个utf-8编码的文本,这时候就需要设置cmd的代码页为65100. 也就是 chcp 65001 这条命令.这样设置可以临时生效. 如何要永久生效,需要在注册表中修改. ...

  8. JS 事件绑定、事件监听、事件委托详细介绍

    原:http://www.jb51.net/article/93752.htm 在JavaScript的学习中,我们经常会遇到JavaScript的事件机制,例如,事件绑定.事件监听.事件委托(事件代 ...

  9. 手把手教你学习R语言

    本文为带大家了解R语言以及分段式的步骤教程! 人们学习R语言时普遍存在缺乏系统学习方法的问题.学习者不知道从哪开始,如何进行,选择什么学习资源.虽然网络上有许多不错的免费学习资源,然而它们多过了头,反 ...

  10. centos7 彻底卸载PHP7

    [root@xxx php-memcached]# rpm -qa | grep php php70w-common--.w7.x86_64 php70w-devel--.w7.x86_64 php7 ...