安卓ConstraintLayout布局

來源:互聯網
上載者:User

標籤:tab   tla   bottom   near   最小   baseline   外邊距   int   tle   

安卓除了有6種最基本的布局線性布局(LinearLayout)、相對布局(RelativeLayout)、幀布局(FrameLayout)、網格布局(GridLayout)、絕對布局(AbsoluteLayout)、表格版面配置(TableLayout)外還有一些較複雜的布局,如ConstraintLayout。
1、優點
調整控制項的位置和大小時更加靈活,功能更強大。
2、繼承關係
和其他布局一樣繼承自ViewGroup。
3、新特性
相對定位:
<Button android:id="@+id/buttonA" ... />
<Button android:id="@+id/buttonB" ...
app:layout_constraintLeft_toRightOf="@+id/buttonA" />
按鈕b的靠右對齊按鈕a

  • 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 // 尾部向尾部對齊
    外邊距:
    <android.support.constraint.ConstraintLayout ...>
    <Button android:id="@+id/button" ...
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent/>
    <android.support.constraint.ConstraintLayout/>
    空間置中效果
    傾向:
    <android.support.constraint.ConstraintLayout ...>
    <Button android:id="@+id/button" ...
    app:layout_constraintHorizontal_bias="0.3"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent/>
    <android.support.constraint.ConstraintLayout/>
    左邊佔0.3,右邊佔0.7
    可見度的表現:
    尺寸約束:
    android:minWidth 設定布局的最小寬度
    android:minHeight 設定布局的最小高度
    CHAIN:
    協助工具輔助:

安卓ConstraintLayout布局

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.