ConstraintLayout 約束布局

2021-08-01 14:49:17 字數 1688 閱讀 9463

使用constraintlayout需要我們新增如下依賴:

compile 『com.android.support.constraint:constraint-layout:1.0.0-alpha4』

//偏離父容器左邊緣的距離為父容器寬度的25%

//偏離父容器上邊緣的距離為父容器高度的25%

guideline可以使用以下三個屬性之一:

layout_constraintguide_begin:指示線距離父容器左邊緣的絕對距離

layout_constraintguide_end:指示線距離父容器右邊緣的絕對距離

layout_constraintguide_percent:指示線距離父容器左邊緣的距離,這個屬性的值是乙個百分比,表示距離佔父容器寬度的比例

android:layout_width="0dp"

android:layout_height="wrap_content"

android:src="@drawable/grass"

表示此控制項與某個控制項水平對齊

表示此控制項在布局中x軸或y軸的絕對座標點。如圖**3

目標消失後的margin

//the left margin to

usewhen the target is gone.

//the top margin to

usewhen the target is gone.

//the right margin to

usewhen the target is gone

//the bottom margin to

usewhen the target is gone.

ConstraintLayout 約束布局

在以前,android是使用布局如linearlayout relativelayout等來構建頁面,但這些布局使用起來很麻煩,並且經常需要一層一層巢狀,寫乙個簡單的頁面就需要費很大的勁。所以在16年i o大會上,google發布了全新的布局 constraintlayout,其他布局和constr...

約束布局ConstraintLayout總結

約束顧名思義,就是將該view約束到指定的view上 包括外層的constraintlayout和其他的布局 實現位置的定位。因此有時候可能需要更多的定位去約束控制項的位置,強大的功能,靈活的使用給上手帶來了一點點的難度,很多開發者望而生畏。其實掌握之後,真的越用越舒服!constraintlayo...

ConstraintLayout 相關用法

優勢 有效地解決布局巢狀過多問題以提高效能,使用約束的方式來指定各個控制項之間的相對位置關係,類似於relativelayout,但比其更加強大。解析constraintlayout的效能優勢 郭霖大大的constraintlayout視覺化介面操作 鴻洋大大的xml 相關操作 build.grad...