约束布局的使用(二)

2023-11-06

主要介绍app:layout_constraintWidth_max、app:layout_constrainedWidth、app:layout_constraintDimensionRatio和Guideline的使用

一、app:layout_constraintWidth_max、app:layout_constrainedWidth、app:layout_constraintDimensionRatio的使用

<?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">

    <!--
            app:layout_constrainedWidth="true",此属性默认为false
            android:layout_width,值为“wrap_content”与“0dp”时,约束才能生效
            app:layout_constraintWidth_max="100dp",此属性必须与两个属性同时使用
    -->

    <TextView
        android:id="@+id/tv_first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00ff00"
        android:textSize="20sp"
        app:layout_constrainedWidth="true"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_max="100dp"
        tools:text="壮士一去不复还" />

    <TextView
        android:id="@+id/tv_second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff0000"
        android:textSize="20sp"
        app:layout_constrainedWidth="false"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_first"
        app:layout_constraintWidth_max="100dp"
        tools:text="风萧萧兮易水寒" />

    <!--
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintDimensionRatio="1:2",此时代表宽高比=1:2
            这种情况是本来是宽随高走的,但是经过测试发现是高随宽走,宽的最大值是跟屏幕宽相匹配,高是宽的两倍。
            很费解。
    -->
    <TextView
        android:id="@+id/tv_third"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#0000ff"
        android:textSize="20sp"
        app:layout_constraintDimensionRatio="1:2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_second"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />

    <!--
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:2"
            这种情况是高随宽走,宽包裹内容,宽的最大值是跟屏幕宽相匹配。
            高是宽的两倍
    -->
    <TextView
        android:id="@+id/tv_forth"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:background="#00fafa"
        android:textSize="20sp"
        app:layout_constraintDimensionRatio="1:2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_third"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />


</androidx.constraintlayout.widget.ConstraintLayout>

二、app:layout_constraintDimensionRatio的使用

<?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">


    <!--
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="H,2:1"
        高将按照2:1的比例展示(实质是高是宽的1/2),但是宽将会按照所给约束进行
    -->
    <TextView
        android:id="@+id/tv_fifth"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ff4b4d"
        android:textSize="20sp"
        app:layout_constraintDimensionRatio="H,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?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">

    <!--
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="W,2:1"
        宽将按照2:1的比例展示(实质是宽是宽的1/2),但是宽将会按照所给约束进行展示
    -->
    <TextView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#00ff00"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="W,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒"
       />
</androidx.constraintlayout.widget.ConstraintLayout>
<?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">


    <!--
        android:layout_width="100dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="H,2:1"
        宽将会按照100dp展示,高是宽的1/2
    -->
    <TextView
        android:id="@+id/tv_fifth"
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:background="#ff4b4d"
        android:textSize="20sp"
        app:layout_constraintDimensionRatio="H,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />


    <!--
        android:layout_width="0dp"
        android:layout_height="100dp"
        app:layout_constraintDimensionRatio="H,2:1"
        宽将会按照自己的约束展示,高是给定的100dp
    -->
    <TextView
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="#00ff00"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="H,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?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">

    <!--
        android:layout_width="100dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="W,2:1"
        宽将按照100dp展示,但是高将会是宽的2倍
    -->
    <TextView
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:background="#00ff00"
        android:textSize="20sp"
        app:layout_constraintDimensionRatio="W,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />

    <!--
        android:layout_width="0dp"
        android:layout_height="100dp"
        app:layout_constraintDimensionRatio="W,2:1"
        高将按照100dp展示,但是宽将会是高的2倍
    -->
    <TextView
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="#ff0000"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="W,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintWidth_default="percent"
        tools:text="风萧萧兮易水寒" />
</androidx.constraintlayout.widget.ConstraintLayout>

三、Guideline的使用

<?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">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="100dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="100dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintLeft_toLeftOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="@id/guideline1" />

</androidx.constraintlayout.widget.ConstraintLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

约束布局的使用(二) 的相关文章

  • vc++6.0 配置opengl

    vc 6 0 配置opengl 坑 解决安装OpenGL时程序运行提示glut32 dll丢失的问题 在安装OpenGL的时候 很多同学都出现了一个问题 在按照教程配置好OpenGL后运行测试程序 编译通过 但运行时出现 计算机丢失glut
  • vue 原生高德地图 单个定位点,定位 移动

    下载 高德地图 npm i amap amap jsapi loader save 导入 import AMapLoader from amap amap jsapi loader 实例化地图控件 initMap lng lat name
  • Altium Designer PCB板框扩大

    Altium Designer PCB板框扩大 AD PCB板框调整 平时我们用AD设计PCB板时 大多数人都需要裁剪PCB板 但是PCB板框的扩大接触少之又少 前段时间 设计了一个天线整列需要扩大PCB板框 在此记录方法 希望对大家有所帮
  • Elementui el-input 输入框校验以及表单校验

    一 常用的 element ui el input 输入框 1 过滤字母e 在js中属于数字 但是正则匹配 d 是拦不住字母e 的
  • IDE的一些常用快捷键

    文章目录 1 IDEA中一些常用的快捷键 2 IDEA中进行Debug时的一些常用快捷键 3 maven中的一些常用设置及命令 4 Linux中的一些快捷键 4 1 Linux中的一些常用命令 5 在浏览器中的一些常用快捷键 6 IDEA中
  • DDL在mysql中的基本操作

    1 DDL数据库操作 查询 show databases 查询当前的数据库 select databases 如果想要查询当前所在数据库则用此语句 一定要记得此处必须要加括号 创建 create database if not exists
  • clion-debug调试步骤

    文章目录 clion debug调试方法 先来一道水题 方便大家理解 操作细节 1 打断点 2 点击debug 3 输入数据 4 下一条指令 clion debug调试方法 脱坑神器 先来一道水题 方便大家理解 题目要求 获取两个输入a b
  • Springboot 配置类( @Configuration) 不能使用@Value注解从application.yml中加载值

    问题 在Springboot应用中 通过Spring context 版本4 3 6 的 Configuration注解配置类 使用 Value注解从application yml配置文件中加载属性 但是总是报找不到 设置缺省值 则获取到的
  • Linux安装安全狗

    一 说明 1 服务器运维 用的阿里云服务器 没用阿里云的安全服务 2 系统 CentOS7 系统 CentOS8 均可安装 3 安装用的是安全狗的免费版 4 安装前 先注册安全狗的云账户 安装好后需要登录此用户 二 下载与安装 1 下载地址
  • 思林杰科技通过注册:应收账款余额1.87亿 占营收比例160%

    雷递网 雷建平 2月18日报道 广州思林杰科技股份有限公司 简称 思林杰科技 日前通过注册 准备在科创板上市 计划募资5 57亿元 其中 2 67亿元用于嵌入式智能仪器模块扩产建设项目 1 6亿元用于研发中心建设项目 1 3亿元用于补充运营
  • 在Windows下安装GmSSL

    本文属于 GmSSL国密加密算法库使用系列教程 之一 欢迎查看其它文章 在Windows下安装GmSSL 一 关于GmSSL 二 编译工具准备 1 安装VS2017 2 安装ActivePerl 3 安装NASM 三 GmSSL源码准备 四
  • python:最小二乘法拟合原理及代码实现

    这里写目录标题 原理 代码实现 原理 最小二乘法适用于对处理的一堆数据 不必精确的经过每一点 而是根据图像到每个数据点的距离和最小确定函数 需要注意的是 最小二乘是对全局进行拟合优化 对噪声比较敏感 所以如果有噪声比较大的观测值会影响拟合结
  • 2023-02-01 读书笔记:《有趣的统计》-1-基础知识

    2023 02 01 读书笔记 有趣的统计 1 基础知识 75招学会数据分析 2014 Doctor Bruce Frey 序 统计学 最初 用于确定某些事情发生的可能性 不断发展 根据样本数据准确推断总体数据特征的方法 推论统计学 Hac
  • springBoot中使用rabbitMQ以及消息丢失问题

    一 rabbitMQ中常用的交换机 图源自官网 https www rabbitmq com getstarted html Direct exchange 直连交换机 一个生产者 一个交换机 两个队列 两个消费者 根据消息发送时携带的路由
  • Docker构建Springboot项目,并发布测试

    把SpringBoot项目打包成Docker镜像有两种方案 全自动化 先打好docker镜像仓库 然后在项目的maven配置中配置好仓库的地址 在项目里配置好Dockerfile文件 这样可以直接在idea中打包好后自动上传到镜像仓库 然后
  • 第一章 单机应用到分布式架构演进

    1 传统单机 分布式架构演进历史 单机架构 优点 易于测试 便于集成 小型项目友好 缺点 开发速度慢 启动时间长 依赖庞大 分布式架构 SOA Service Oriented Architecture 面向服务的架构 其中包含多个服务 服
  • Vue 自定义tree组件

    这是一个递归组件 首先组件是可以在模板里通过 export default 的 name 来调用本身 只是一个思路 写的比较简单 直接上代码
  • tensorflow学习笔记4(神经网络八股)

    2 train test 告知要喂入网络的训练集和测试集是什么 3 在Sequential中搭建神经网络结构 逐层描述每层网络 相当于走了一边前向传播 4 在compile配置训练方法 选择何种优化器 更新网络参数使用 何种损失函数 何种评

随机推荐

  • fcm算法的MATLAB实现,FCM算法的matlab程序(初步)

    FCM算法的matlab程序 1 采用iris数据库 iris data txt 5 1 3 5 1 4 0 2 4 9 3 1 4 0 2 4 7 3 2 1 3 0 2 4 6 3 1 1 5 0 2 5 3 6 1 4 0 2 5 4
  • 第十届蓝桥杯(省赛)之Fibonacci数列和黄金分割

    一 version1 遇到的问题 F数组存储的数据超过long表示范围 import java math BigDecimal import java math BigInteger import java util Scanner pub
  • 批量关闭公众号推送_新功能!微信可以批量“取关”公众号啦!

    微信内测新功能 一如既往地引起了热议 有人说 批量关闭接收推送等同于批量取关 有人说 好内容的阅读要涨了 谁说对了 今天下午 有多位读者向WHO哥爆料称 收到 微信公众平台 的通知消息 微信自动检测出 你有多个关注的订阅号长时间未读 可以选
  • 微服务为什么一定要选spring cloud?

    作者 董添 李秉谦 网易乐得技术团队 来自 http tech lede com 现如今微服务架构十分流行 而采用微服务构建系统也会带来更清晰的业务划分和可扩展性 同时 支持微服务的技术栈也是多种多样的 本系列文章主要介绍这些技术中的翘楚
  • 微信公众号网页分享,脱坑思路

    1 绑定域名 首先确定使用的域名是否和微信公众号接口权限 网页服务 网页授权配置的js域名是否一致 2 引入JS文件 在需要调用JS接口的页面引入如下JS文件 支持https http res wx qq com open js jweix
  • 位置式PID控制算法

    刚好前不久搞过PID 部分程序如下 仅供参考 在使用单片机作为控制cpu时 请稍作简化 具体的PID参数必须由具体对象通过实验确定 由于单片机的处理速度和ram资源的限制 一般不采用浮点数运算 而将所有参数全部用整数 运算到最后再除以一个2
  • 【爬坑之路一】windows系统下更新升级node版本【亲测有效】

    前言 一定要看到最后 项目开发中 需要升级 node 版本 本着不想卸载 node 再重新安装的原则 因为node 的环境配置以及各种相关配置有些繁琐 所以就想着使用 命令的方式进行升级 在网上找了一些升级 node 的命令 最常见的是安装
  • 分布式锁实战

    示例代码 maven引入 maven引入
  • 与困难的利益相关者和团队成员打交道

    经历分歧和冲突是我们作为产品经理和产品所有者的工作的一部分 我们与来自不同部门的广泛人员合作 这是很自然的 我们并不总是同意 有时会发生冲突 但是建设性地解决冲突可能具有挑战性 本文分享了我与困难者打交道并成功解决冲突的建议 这是一个共同的
  • 【性能】JDK和Jmeter的安装与配置

    目录 一 JDK环境配置 1 下载JDK 2 配置JDK环境 二 Jmeter环境配置 1 下载Jmeter 2 配置Jmeter环境 更多干货 完整版文档下载方式 一 JDK环境配置 1 下载JDK 官网下载地址 http www ora
  • C++中print和printf的区别

    print与printf的区别 1 print 中不能使用 s d 或 c 2 print 自动换行 printf 没有自动换行 转载于 https www cnblogs com yun an p 11070228 html
  • MySQL 按照条件统计多张表记录数总数

    一 诉求 数据库中有 4 张订单表 分别为 tbl test order01 tbl test order02 tbl test order03 tbl test order04 分别用于存储四个季度的订单表数据 各表的表结构均相同 以 t
  • Office 2021 简体中文离线安装包下载地址

    Office 2021 简体中文离线安装包下载地址 一 专业增强版 强烈推荐 http officecdn microsoft com pr 492350f6 3a01 4f97 b9c0 c7c6ddf67d60 media zh cn
  • web前端技术笔记()js对象方法讲解

    不带参函数的调用
  • python sqlalchemy 动态创建表,,或动态修改__tablename__的两种方法

    最近在学习sqlalchemy 有个动态修改 tablename 的需求 搜索了好几天 没有太完美的答案 要么看不懂 要么比较古老了 通过研究 整理以下几种sqlalchemy动态修改 tablename 的方法 一 函数封装table m
  • springboot+vue+elementui+阿里云oss上传文件

    才做完课程设计没多久 本来打算早点写这一篇文章 但是由于太懒了 就拖延了好几天 今天没什么事情 就打算写下一篇关于文件上传我文章 希望可以帮助到大家 需要准备 配置好maven 购买阿里云oss 第一步 导入指定的依赖
  • 浅谈测试用例设计

    一 测试用例为什么存在 1 1 定义 测试用例 Test Case 是指对特定的软件产品进行测试任务的描述 体现测试方案 方法 技术和策略 测试用例内容包括测试目标 测试环境 输入数据 测试步骤 预期结果 测试脚本等 最终形成文档类的输出
  • 华为交换机SSH和telnet登录配置

    华为交换机SSH和telnet登录配置 一 网络拓扑 二 SW2配置telnet 1 SW2配置 2 R1登录验证 三 SW2的ssh登录配置 1 生成本地密钥对 2 SW2配置命令 3 R1登录 四 配置console口密码 1 配置命令
  • 红黑树

    写在前面 当在10亿数据进行不到30次比较就能查找到目标时 不禁感叹编程之魅力 人类之伟大呀 学红黑树有感 终于 在学习了几天的红黑树相关的知识后 我想把我所学所想和所感分享给大家 红黑树是一种比较难的数据结构 要完全搞懂非常耗时耗力 红黑
  • 约束布局的使用(二)

    主要介绍app layout constraintWidth max app layout constrainedWidth app layout constraintDimensionRatio和Guideline的使用 一 app la