ConstraintLayout基础

这种布局我先做个简单的介绍,我分段讲,这是相对布局的加强版

基本使用(模拟相对布局)

 

 如何实现这种布局通过ConstraintLayout

直接上代码,这种怎么解释都没用,你自己试一下就会用了,我只能告诉你经验。布局编辑器可以拖,但是我们推荐直接写,写起来比拖舒服

代码

    <TextView
        android:background="@color/black"
        android:textColor="@color/white"
        android:textSize="45sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        tools:layout_editor_absoluteX="84dp"
        tools:layout_editor_absoluteY="153dp" />

解释

就中间隔出来的这两句,你直接输入toptotop代码编辑器自动弹出,意思也明显,就是控件的top靠parent的top,parent就是container

控件有四条边,名字叫 start top end bottom你肯定还见过left 和right,这个和start和end一样的。这个是因为有的国家读字,读东西从右向左读,这个布局不一样,我们一般用start 和 end

 

toptotop这种像弹簧一样,两个去拉就是是在中间,一个拉就是靠边

 

 Github地址 下载前给star

 

 

posted @ 2022-11-17 13:41  Z_Chan  阅读(28)  评论(0编辑  收藏  举报