安卓学习10(ConstraintLayout布局)

目标任务:

学习ConstraintLayout布局

预计时间:

2天

完成情况:

1、约束布局ConstraintLayout 是一个ViewGroup,可以在Api9以上的Android系统使用它,它的出现主要是为了解决布局嵌套过多的问题,以灵活的方式定位和调整小部件

2、使用ConstraintLayout

(1)添加依赖

  在app/build.gradle文件中添加ConstraintLayout的依赖:implementation 'com.android.support.constraint:constraint-layout:1.1.3'

(2)相对定位

(3)角度定位

(4)可以用一个角度和一个距离来约束两个空间的中心

(5)边距

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

 

 

 

 

 

 

例如:

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp" 
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

 

遇到问题:

posted on 2021-02-22 12:39  桑榆非晚柠月如风  阅读(57)  评论(0编辑  收藏  举报