【约束布局】ConstraintLayout 屏障 Barrier 约束 ( 简介 | 屏障适用场景 | 位置说明 | 相关属性 | 可视化操作 | 代码示例 | 总结 )(二)

简介: 【约束布局】ConstraintLayout 屏障 Barrier 约束 ( 简介 | 屏障适用场景 | 位置说明 | 相关属性 | 可视化操作 | 代码示例 | 总结 )(二)

VI . 屏障 Barrier 可视化操作


1 . 添加屏障线 : 如下图所示 , 选择 “Add Vertical Barrier” 选项 , 可以添加垂直方向的屏障 ; 选择 “Add Horizontal Barier” 选项 , 可以添加水平方向的屏障 ;


image.png



2 . 为屏障配置包含的组件 : 在 Component Tree 面板中 , 鼠标左键按住左键 , 拖动到 Barrier 中 , 即可为 Barrier 屏障 添加包含的组件 ;

image.png




3 . 设置屏障方向 : 选中要编辑的 屏障 Barrier 组件 , 在 Attributes 面板中的 Common Attributes 选项卡中的 barrierDirection 中选择 6 66 个方向 ;



image.png



VII . 屏障 Barrier 代码示例


1 . 代码示例 :


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <!-- 屏障中较小的组件 -->
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <!-- 屏障中较大的组件 -->
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World! Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/button1"
        app:layout_constraintVertical_bias="0.2" />
    <!-- 左侧屏障 -->
    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="left"
        app:constraint_referenced_ids="button2,button1" />
    <!-- 顶部屏障 -->
    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="top"
        app:constraint_referenced_ids="button1,button2" />
</androidx.constraintlayout.widget.ConstraintLayout>



2 . 效果展示 :



image.png



VIII . 屏障 Barrier 总结


屏障 Barrier 总结 :



① 设置组件包含 : app:constraint_referenced_ids=“button2,button1” ; 组件 ID 之间使用逗号隔开 ;


② 设置方向 : app:barrierDirection=“top” ; 可选属性值 left ( start ) , right ( end ) , top , bottom ;


目录
相关文章
|
存储 机器学习/深度学习 缓存
一看就懂!图解 Kotlin SharedFlow 缓存系统
一看就懂!图解 Kotlin SharedFlow 缓存系统
707 2
|
测试技术 API 网络架构
利用百度云盘API上传文件至百度云盘
一、获取Access Token示例 1. 请您将以下HTTP请求直接粘贴到浏览器地址栏内,并按下回车键。 https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=L6g70tBRRIXLsY0Z3...
4829 0
|
8月前
|
数据采集 人工智能 JavaScript
OpenClaw 阿里云/本地部署+Apify MCP集成指南:强化全网结构化数据高效采集教程
现在AI编程工具的联网数据采集能力,往往卡在“JS渲染页面抓不到、反爬机制绕不开、数据格式不规范”三大痛点上。OpenClaw作为灵活的AI Agent平台,2026年通过与Apify生态深度集成,完美解决了这些问题——借助Apify的Agent Skills与MCP Server,OpenClaw不仅能突破JS渲染与反爬限制,还能直接输出结构化表格数据,让数据采集从“文本摘要”升级为“即用型数据集”。
746 0
|
Android开发 开发者 索引
Android实战经验之如何使用DiffUtil提升RecyclerView的刷新性能
本文介绍如何使用 `DiffUtil` 实现 `RecyclerView` 数据集的高效更新,避免不必要的全局刷新,尤其适用于处理大量数据场景。通过定义 `DiffUtil.Callback`、计算差异并应用到适配器,可以显著提升性能。同时,文章还列举了常见错误及原因,帮助开发者避免陷阱。
1663 9
|
开发工具 Android开发 git
同步、更新、下载Android Source & SDK from 国内镜像站
转自: 同步、更新、下载Android Source & SDK from 国内镜像站 Download the android source from china mirrors     以前都是从Google的站点下载同步更新的,但是现在有了国内的镜像站点就好多了 帮助  https://wiki.
5780 0
|
SQL 监控 关系型数据库
多个表同时更新的SQL技巧与方法
在数据库管理中,有时需要同时对多个表进行更新操作,以满足复杂的业务需求或数据一致性要求
2008 0
|
Linux
Linux的strings命令如何使用?
【6月更文挑战第3天】Linux的strings命令如何使用?
657 4
|
存储 算法 安全
密码算法的分类
【8月更文挑战第23天】
1493 0
|
监控 数据中心
【专栏】交换机电口和光口的定义、特点及应用场景,做网络的这个常识得懂!
【4月更文挑战第28天】本文探讨了交换机电口和光口的定义、特点及应用场景。电口,常见于局域网和办公环境,成本低但传输距离有限;光口,适用于长距离、高速率传输,如城域网、数据中心,具有抗干扰强但成本高的特点。选择接口时需考虑传输距离、速率和成本,注意兼容性、线缆选择及维护管理。理解两者差异有助于网络规划和管理。
2247 0