温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

安卓ConstraintLayout布局

发布时间:2020-09-06 11:12:07 来源:网络 阅读:975 作者:sunshineHJ 栏目:移动开发

安卓除了有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:
    辅助工具:
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI