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 @   Z_Chan  阅读(35)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示