Constraintlayout便查手冊

Constraintlayout便查手冊

摘取自ConstraintLayout

Relative positioning (相對定位)

[圖片上傳失敗...(image-1013da-1529032552415)]

<Button android:id="@+id/buttonA" ... />
<Button android:id="@+id/buttonB"
        app:layout_constraintLeft_toRightOf="@+id/buttonA" />

layout_constraintLeft_toLeftOf
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBaseline_toBaselineOf
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf

Margins

普通的 margin 依然適用

android:layout_marginStart
android:layout_marginEnd
android:layout_marginLeft
android:layout_marginTop
android:layout_marginRight
android:layout_marginBottom

Margins when connected to a GONE widget

當(dāng)位置約束目標(biāo)的可見性為View.GONE時答姥,還可以使用以下屬性指示要使用的不同邊距值:
layout_goneMarginStart
layout_goneMarginEnd
layout_goneMarginLeft
layout_goneMarginTop
layout_goneMarginRight
layout_goneMarginBottom

Centering positioning and bias(居中定位)

<android.support.constraint.ConstraintLayout ...>
  <Button android:id="@+id/button" ...
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent/>
</>
<!-- 除非 Button 與父布局一樣大, 否則會居中 -->

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

偏差 : 用下面參數(shù), 默認(rèn)0.5--為居中
layout_constraintHorizontal_bias
layout_constraintVertical_bias

Circular positioning (Added in 1.1)

layout_constraintCircle : references another widget id(引用另一個小部件ID)
layout_constraintCircleRadius : the distance to the other widget center(到其他小部件中心的距離"xxdp")
layout_constraintCircleAngle : which angle the widget should be at (in degrees, from 0 to 360) (角度)

Visibility behavior

Dimensions constraints(尺寸限制)

Minimum dimensions on ConstraintLayout

Those minimum and maximum dimensions will be used by ConstraintLayout when its dimensions are set to WRAP_CONTENT.
是不是 要使用 min or max

android:minWidth -- set the minimum width for the layout
android:minHeight -- set the minimum height for the layout
android:maxWidth -- set the maximum width for the layout
android:maxHeight -- set the maximum height for the layout

Widgets dimension constraints

android:layout_width and android:layout_height attributes in 3 different ways:
width 和 height 有下面三種

  • Using a specific dimension (such 123dp)
  • Using WRAP_CONTENT, which will ask the widget to compute its own size
  • Using 0dp, which is the equivalent of "MATCH_CONSTRAINT"

MATCH_PARENT 不再適用于ConstraintLayout

WRAP_CONTENT : enforcing constraints (Added in 1.1)

If a dimension is set to WRAP_CONTENT, in versions before 1.1 they will be treated as a literal dimension -- meaning, constraints will not limit the resulting dimension. While in general this is enough (and faster), in some situations, you might want to use WRAP_CONTENT, yet keep enforcing constraints to limit the resulting dimension. In that case, you can add one of the corresponding attribute:
使用 WRAP_CONTENT 但仍然想使用約束 ????

app:layout_constrainedWidth=”true|false”
app:layout_constrainedHeight=”true|false”

MATCH_CONSTRAINT dimensions (Added in 1.1)

MATCH_CONSTRAINT 有這么幾個參數(shù)可以使用

layout_constraintWidth_min and layout_constraintHeight_min : will set the minimum size for this dimension(設(shè)置最小)
layout_constraintWidth_max and layout_constraintHeight_max : will set the maximum size for this dimension(設(shè)置最大)
layout_constraintWidth_percent and layout_constraintHeight_percent : will set the size of this dimension as a percentage of the parent(設(shè)置父布局的 %)

Min and Max

The value indicated for min and max can be either a dimension in Dp, or "wrap", which will use the same value as what WRAP_CONTENT would do.
min和max指示的值可以是Dp中的一個維度,也可以是“wrap”揭糕,它將使用與WRAP_CONTENT相同的值竞端。

Percent dimension(百分比設(shè)置)

如果想使用百分比, 需要設(shè)置一下內(nèi)容

  • The dimension should be set to MATCH_CONSTRAINT (0dp)(尺寸設(shè)置為0dp或者 match_constaraint)
  • The default should be set to percent app:layout_constraintWidth_default="percent" or app:layout_constraintHeight_default="percent" (默認(rèn)值寫百分比)
  • Then set the layout_constraintWidth_percent or layout_constraintHeight_percent attributes to a value between 0 and 1 (這兩個參數(shù) 0-1 之間)
Ratio

參數(shù)可以設(shè)置為浮點(diǎn)值(0.5)或者"width:height"(1:1)

<Button android:layout_width="wrap_content"
    android:layout_height="0dp"
    app:layout_constraintDimensionRatio="1:1" />
<!-- 注意0dp -->

app:layout_constraintDimensionRatio

<Button android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintDimensionRatio="H,16:9"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>
<!--設(shè)置 W 或者 H 來代表約束邊-->

Chains 鏈

ChainStyle

layout_constraintHorizontal_chainStyle or layout_constraintVertical_chainStyle
When setting the attribute layout_constraintHorizontal_chainStyle or layout_constraintVertical_chainStyle on the first element of a chain, the behavior of the chain will change according to the specified style (default is CHAIN_SPREAD).

  • sprread(default) -- average parent <-> view && view<-> view
  • spread_inside -- average view <-> view , adjoin parent <-> view
  • packed -- average parent <->view , adjoin view <-> view
  • width or height is 0dp -- adjoin 0dp`s view
weight 權(quán)重

當(dāng) 寬高 MATCH_CONSTRAINT(0dp)的時候, 用下面的方法設(shè)置權(quán)重

layout_constraintHorizontal_weight and layout_constraintVertical_weight

android.support.constraint.Guideline

A Guideline can be either horizontal or vertical

  • specifying a fixed distance from the left or the top of a layout (layout_constraintGuide_begin)(指定布局左側(cè)或頂部的固定距離)
  • specifying a fixed distance from the right or the bottom of a layout (layout_constraintGuide_end)(從布局的右側(cè)或底部指定固定距離)
  • specifying a percentage of the width or the height of a layout (layout_constraintGuide_percent)(指定布局的寬度或高度的百分比)
  • android:orientation 方向
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末屎即,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子事富,更是在濱河造成了極大的恐慌技俐,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,635評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件统台,死亡現(xiàn)場離奇詭異雕擂,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)贱勃,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評論 3 399
  • 文/潘曉璐 我一進(jìn)店門井赌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人贵扰,你說我怎么就攤上這事仇穗。” “怎么了戚绕?”我有些...
    開封第一講書人閱讀 168,083評論 0 360
  • 文/不壞的土叔 我叫張陵纹坐,是天一觀的道長。 經(jīng)常有香客問我列肢,道長恰画,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,640評論 1 296
  • 正文 為了忘掉前任瓷马,我火速辦了婚禮拴还,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘欧聘。我一直安慰自己片林,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評論 6 397
  • 文/花漫 我一把揭開白布怀骤。 她就那樣靜靜地躺著费封,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蒋伦。 梳的紋絲不亂的頭發(fā)上弓摘,一...
    開封第一講書人閱讀 52,262評論 1 308
  • 那天,我揣著相機(jī)與錄音痕届,去河邊找鬼韧献。 笑死,一個胖子當(dāng)著我的面吹牛研叫,可吹牛的內(nèi)容都是我干的锤窑。 我是一名探鬼主播,決...
    沈念sama閱讀 40,833評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼嚷炉,長吁一口氣:“原來是場噩夢啊……” “哼渊啰!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起申屹,我...
    開封第一講書人閱讀 39,736評論 0 276
  • 序言:老撾萬榮一對情侶失蹤绘证,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后哗讥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體迈窟,經(jīng)...
    沈念sama閱讀 46,280評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評論 3 340
  • 正文 我和宋清朗相戀三年忌栅,在試婚紗的時候發(fā)現(xiàn)自己被綠了车酣。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,503評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡索绪,死狀恐怖湖员,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情瑞驱,我是刑警寧澤娘摔,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站唤反,受9級特大地震影響凳寺,放射性物質(zhì)發(fā)生泄漏鸭津。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評論 3 333
  • 文/蒙蒙 一肠缨、第九天 我趴在偏房一處隱蔽的房頂上張望逆趋。 院中可真熱鬧,春花似錦晒奕、人聲如沸闻书。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽魄眉。三九已至,卻和暖如春闷袒,著一層夾襖步出監(jiān)牢的瞬間坑律,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評論 1 272
  • 我被黑心中介騙來泰國打工囊骤, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留脾歇,地道東北人。 一個月前我還...
    沈念sama閱讀 48,909評論 3 376
  • 正文 我出身青樓淘捡,卻偏偏與公主長得像藕各,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子焦除,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評論 2 359

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,345評論 0 10
  • 簡書MarkDown支持有點(diǎn)問題激况,請?zhí)D(zhuǎn)到我博客查看該篇博客:http://weiyf.cn/2017/03/10...
    衛(wèi)裕發(fā)閱讀 4,699評論 0 4
  • ?對不起乌逐,我的父母 給你們打電話的時候太少 回家的次數(shù)更是屈指可數(shù) 策劃這份工作太忙太累太晚 下班后就一句多余的話...
    策劃圈群主艾倫閱讀 275評論 0 0
  • 感覺家里親戚做面食很快,這郭家一伙說話也很快创葡。得對付得了機(jī)器浙踢。 龍在教師崗位見人見多,反應(yīng)比較快灿渴,說話描述好玩的事...
    治青閱讀 145評論 0 0
  • 準(zhǔn)備期:資源+方案 時間:活動開始前2個月 1洛波、資源確認(rèn) ①市場渠道(如應(yīng)用寶、360手機(jī)衛(wèi)士骚露、百度手機(jī)助手蹬挤、PP...
    _Sya閱讀 266評論 0 0