1. 程式人生 > >Android 開發 CoordinatorLayout 協調者佈局 與 ConstraintLayout約束佈局 兩者的關係

Android 開發 CoordinatorLayout 協調者佈局 與 ConstraintLayout約束佈局 兩者的關係

  在摸索新技術是發現CoordinatorLayout 與 ConstraintLayout 會有衝突關係,所以就研究了一下他們之間的不相容,被影響的方面.其實某種程度上來說是CoordinatorLayout與其他Layout佈局之間的關係.

 

  首先說明一下:

  CoordinatorLayout:  Material Design 的根佈局,作為協調Material下所有控制元件的動畫聯動.所以被稱為協調者佈局

  ConstraintLayout:    google為了將佈局扁平化,減少巢狀而設計的約束佈局

 

  它們的關係

  1.CoordinatorLayout必需做為根佈局存在,才能使它的子view或者layout都有動畫關聯效果

  2.ConstraintLayout 不可以作為跟佈局巢狀 CoordinatorLayout,否則會讓全部Material都沒有動畫效果

  3.ConstraintLayout不可以巢狀AppBarLayout佈局,一樣會影響Material都沒有動畫效果

  4.ConstraintLayout最好巢狀在最後一層的佈局裡,作為為其他控制元件提供確定位置的佈局