美文网首页
AndroidのConstraintLayout

AndroidのConstraintLayout

作者: 耑意儿 | 来源:发表于2019-08-15 20:06 被阅读0次
目录:
1. Constraintlayout的基本属性
2. ConstraintLayout嵌套SrcollView
3. 布局辅助线:`Guideline`
Android小仙

参考资料:掘金-ConstraintLayout在项目中实践与总结

1. Constraintlayout的基本属性

对于我这样的新手来说,ConstraintLayout使用起来实在是太费神了
我花了大半个下午写了一个用其他布局方式半小时能写完的布局,晕(((φ(◎ロ◎;)φ)))
网上一看,都说ConstraintLayout的出现是为了解决布局嵌套过多的问题,以灵活的方式定位和调整小部件。

太难了太难了,崇拜领导

1.1 配置

根目录的build.gradle

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

app模块下的build.gralde

compile 'com.android.support.constraint:constraint-layout:1.0.2'
1.2 基本属性

1.2.1 相对位置
约束左边-相对于目标的位置

layout_constraintLeft_toLeftOf // 约束左侧,在依赖控件的左边
layout_constraintBaseline_toBaselineOf // 约束基准线,在依赖控件的基准线上
layout_constraintStart_toEndOf // 约束开头,在依赖控件的结束点上

1.2.2 边距

android:layout_marginStart // 普通边距
layout_goneMarginStart  // 特殊边距 - 被依赖控件消失时的边距

1.2.3 居中
同时约束到父控件的左右边,为水平居中

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

1.2.4 居中后偏移

layout_constraintHorizontal_bias  // 偏移值取0~1 百分比

1.2.5 宽高比例

layout_constraintDimentionRatio

1.2.6 尺寸

layout_constraintWidth_min // 最小宽度
layout_constraintHeight_max // 最大高度
layout_constraintWidth_percent // 相对于父控件的百分比

2. ConstraintLayout嵌套SrcollView

  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0pt"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="30pt">
        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

3. 布局辅助线:Guideline

相关文章

网友评论

      本文标题:AndroidのConstraintLayout

      本文链接:https://www.haomeiwen.com/subject/bcstsctx.html