1. 程式人生 > >android -------- ConstraintLayout Group和goneMargin(五)

android -------- ConstraintLayout Group和goneMargin(五)

前面的文章

此博文主要講解: 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 GroupgoneMargin

前面的文章 此博文主要講解: Group和goneMargin 1:Group 在開發中,有時候需要同時隱藏或者顯示多個控制元件,用Group就可以很好的實現,是一個輔助類,不會繪

android -------- ConstraintLayout GuidelineBarrier

前面的文章 此博文主要講解:Guideline和Barrier Guideline (瞭解,實際使用過程中我使用的不多) 當需要一個任意位置的錨點時,可以使用指示線(Guideline)來幫助定位,指示線實際上是 View 的子類,使用方式和普通的 Vi

Android 進階】仿抖音系列之視訊預覽錄製

大家好,又見面了。在前幾篇中,我們通過2種方式實現了仿抖音的翻頁切換視訊,仿抖音列表播放視訊功能,這一篇,我們來說說視訊的錄製。 【Android 進階】仿抖音系列之翻頁上下滑切換視訊(一) 【Android 進階】仿抖音系列之列表播放視訊(二) 【Android

基於android的網路音樂播放器-網路音樂的搜尋展示

作為android初學者,最近把瘋狂android講義和瘋狂Java講義看了一遍,看到書中介紹的知識點非常多,很難全部記住,為了更好的掌握基礎知識點,我將開發一個網路音樂播放器-EasyMusic來鞏固下,也當作是練練手。感興趣的朋友可以看看,有設計不足的地方也

Android的方法屬性2

pin spinner 城市 android har lap ng- drawable -c 1.RadioButton(單選按鈕)   嵌入到RsdioGroup中實現單選效果   android:checkedButton="radio的id值"   int getC

GoroutinesChannels

試圖 回收 OS 廣播 highlight 發送 lose 停止 bubuko Channels也可以用於將多個goroutine連接在一起,一個Channel的輸出作為下一個Channel的輸入。這種串聯的Channels就是所謂的管道(pipeline)。下面的程序用兩

Android 建立與解析XML—— Dom4j方式

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

CodeMix使用的語言框架:React

在Eclipse中使用React進行程式設計React是一個用於構建使用者介面的JavaScript庫。 它是一個基於宣告和元件的框架。 應用程式可以由多個封裝元件組成,這些元件管理自己的狀態,並在資料更改時有效地更新。 React還可以用於使用React Native為移動應用程式提供支援。 如果您想在Ec

Go學習筆記陣列切片容器

func main() { //定義陣列 數量在型別的前面 var arr [5] int // 不定義值為0 arr1 := [3]int{1} // := 必須賦值 最少賦值1位 arr2 := [...]int{4,5,6,7,8} //...可不規定長度 //二維陣列 var

android 資訊(mms)的故事-- 發彩信

發彩信和發簡訊一樣,在ComposeMessageActivity.java介面都是從onclick()、sendMessage()開始,同樣的傳送前檢查收件人是否有效,和簡訊不一樣的是發彩信的時候郵件地址也是可以做為收件人的,接下來也是WorkingMessage.java的send()方法。&n

【朝花夕拾】Android效能優化篇之Android虛擬機器簡介

前言        Android虛擬機器的使用,使得android應用和Linux核心分離,這樣做使得android系統更穩定可靠,比如程式中即使包含惡意程式碼,也不會直接影響系統檔案;也提高了跨平臺相容性。在Android4.4以前的系統中,Android系統均採用Dalvik作為執行andorid程式的

【朝花夕拾】Android效能優化篇之Android虛擬機器

前言        Android虛擬機器的使用,使得android應用和Linux核心分離,這樣做使得android系統更穩定可靠,比如程式中即使包含惡意程式碼,也不會直接影響系統檔案;也提高了跨平臺相容性。在Android4.4以前的系統中,Android系統均採用Da

說說 Android 的 Material Design 設計——可摺疊式標題欄

1 CollapsingToolbarLayout 佈局 CollapsingToolbarLayout 是基於 Toolbar 的佈局。它可以讓 Toolbar 的效果變得更加華麗。 **注意:**CollapsingToolbarLayout 只能作為 Ap

Android 9 功能 API-----------顯示屏缺口支援劉海屏或凹凸屏

詳細的適配方案,大家可以看我之前的文章: https://blog.csdn.net/wypeng2010/article/details/81019361     Android 9 支援最新的全面屏,其中包含為攝像頭和揚聲器預留空間的螢幕缺口。 通過 

Android 9 功能 API-----------其它一些改變

多攝像頭支援和攝像頭更新 在執行 Android 9 的裝置上,您可以通過兩個或更多物理攝像頭來同時訪問多個視訊流。] 在配備雙前置攝像頭或雙後置攝像頭的裝置上,您可以建立只配備單攝像頭的裝置所不可能實現的創新功能,例如無縫縮放、背景虛化和立體成像。 通過該 API,您還可以呼叫邏輯或融合的攝像

資料結構棧佇列棧的順序儲存結構鏈式儲存結構的實現

一、 實驗目的1. 熟悉棧的特點(先進後出)及棧的抽象類定義;2. 掌握棧的順序儲存結構和鏈式儲存結構的實現;3. 熟悉佇列的特點(先進先出)及佇列的抽象類定義;4. 掌握棧的順序儲存結構和鏈式儲存結構的實現;二、實驗要求1. 複習課本中有關棧和佇列的知識;2. 用C++語言

Retrofit,Okhttp對每個Request統一動態新增header引數

Header How to Add header to Every Request 新增統一通用header, 不會覆蓋前面的header okHttpClient.intercept

立體視覺:演算法應用

本文翻譯的外國學者的一份talk,主要內容是關於立體視覺演算法和應用的基礎知識。限於個人水平,如有疏漏之處請諒解。 大綱 1、介紹 3、視覺匹配演算法 4、計算優化 5、硬體實現 6、應用 代價聚合 幾種support的變化 1、可移動視窗(Shif

大資料架構模式對大資料問題應用解決方案模式並選擇實現它的產品

  簡介   本系列的 第 3 部分 描述了針對最常見的、經常發生的大資料問題及其解決方案的原子模式和複合模式。本文將推薦可以用於架構大資料解決方案的三個解決方案模式。每個解決方案模式都使用了一個複合模式,該模式由邏輯元件構成(參見第 3 部分的介紹)。在本文末尾處,列出了產品和工具清單,它們可對映到每

ReviewBoard 的安裝使用—— RBTools工具的使用

Linux 下開發的人員比較習慣於使用命令列工具,剛才網頁上提交檔案的方式感覺更適合windows 下的開發人員,那ReviewBoard 有沒有提交程式碼的命令列工具呢,那就是RBTools了。 安裝RBTools: pip install RBToo