Android 约束布局 ConstrainLayout min max width

article/2025/10/7 5:13:59

写一个自定义view

package com.anguomob.guidelineimport android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import android.view.Viewclass ZeroView constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) :View(context, attrs, defStyleAttr) {override fun onDraw(canvas: Canvas?) {super.onDraw(canvas)canvas?.drawColor(Color.RED);}}

放到布局当中

<?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"><LinearLayoutandroid:id="@+id/left"android:layout_width="100dp"android:layout_height="match_parent"android:background="@android:color/holo_green_dark"android:orientation="horizontal"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><LinearLayoutandroid:id="@+id/right"android:layout_width="100dp"android:layout_height="match_parent"android:background="@android:color/holo_green_dark"android:orientation="horizontal"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="1231234"app:layout_constraintEnd_toEndOf="@id/right"app:layout_constraintStart_toStartOf="@id/left"app:layout_constraintTop_toTopOf="parent" /><!--        app:layout_constraintWidth_max="200dp"--><com.anguomob.guideline.ZeroViewandroid:id="@+id/tv2"android:layout_width="wrap_content"android:layout_height="40dp"android:maxWidth="200dp"app:layout_constraintEnd_toEndOf="@id/right"app:layout_constraintStart_toStartOf="@id/left"app:layout_constraintTop_toBottomOf="@id/tv" /></androidx.constraintlayout.widget.ConstraintLayout>

maxWidth好像是没有生效。

那我们通过app也就是约束布局自带的属性去约束呢

     app:layout_constraintWidth_max="200dp" 

    <com.anguomob.guideline.ZeroViewandroid:id="@+id/tv2"android:layout_width="wrap_content"android:layout_height="40dp"app:layout_constraintEnd_toEndOf="@id/right"app:layout_constraintStart_toStartOf="@id/left"app:layout_constraintTop_toBottomOf="@id/tv"app:layout_constraintWidth_max="200dp" />

成功


http://chatgpt.dhexx.cn/article/cxZn4MTC.shtml

相关文章

ConstrainLayout 基础教程2,近期想跳槽的程序员必看

特性详解 Visibility behavior (可见性的表现) ConstraintLayout对可见性被标记View.GONE的控件(后称“GONE控件”)有特殊的处理。一般情况下,GONG控件是不可见的,且不再是布局的一部分,但是在布局计算上,ConstraintLayout与传统布局有一个很重要的区别: 传统布局下,…

UGUI源码解析——LayoutElement

一&#xff1a;前言 继承了ILayoutElement和ILayoutIgnorer接口&#xff0c;作为布局元素组件 挂载了Layout Element组件的对象&#xff0c;布局并不会生效&#xff0c;它是受到实现了布局组的控制(HorizontalLayoutGroup、VerticalLayoutGroup、GridLayoutGroup) 二&#xff…

Layui框架的使用技巧

1.选中html代码块&#xff0c;ctrlshift减号- 就会全部折叠 2.加入Thymeleaf模板需要添加命名空间 <!DOCTYPE html> <html xmlns:th"http://www.thymeleaf.org/"></html> 2.1 替换方法 2.2添加 th:fragment 2.3主页面用一行代码替换 3.SpringBo…

UGUI源码解析——LayoutUtility

一&#xff1a;前言 布局的工具类&#xff0c;可以获取到对象的minWidth、preferredWidth、flexibleWidth、minHeight、preferredHeight、layoutPriority的属性值 二&#xff1a;源码解析 ——获取对象属性值的方法 以上方法可以获取到对象的minWidth、preferredWidth、flexi…

Flutter布局指南之深入理解BoxConstraints

点击上方蓝字关注我&#xff0c;知识会给你力量 强烈建议先看下这篇文章——Flutter你竟是这样的布局 不管你是Android开发&#xff0c;还是Flutter开发&#xff0c;当你开始使用Flutter茫茫多的Widget时&#xff0c;可能会猜测Widget在屏幕上的尺寸和位置&#xff0c;但事实上…

vue element-ui el-table表格二次封装 自定义el-table表格组件 vue封装表格组件

CommTable.vue table组件 <template><div><el-table:data"tableData"border:class"tabClass ? tabClass : null":showHeader"showHeader ? showHeader : true":spanMethod"spanMethod ? spanMethod : null"element…

Stage的MinWidth和MinHeight的疑问

设置了Stage的MinWidth和MinHeight,但是显示的时候不是这个高度和宽度&#xff0c;最小化之后再次显示的时候就可以了&#xff0c;奇怪 package stage;import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import jav…

php的width是什么意思,minwidth什么意思?min-width怎么设置

很多人刚刚入门css的新手&#xff0c;不知道minwidth什么意思&#xff1f;min-width怎么设置&#xff0c;下面php中文网就带领大家来学习一下min-width。 一&#xff1a;minwidth什么意思 在css中&#xff0c;minwidth是设置段落的最小宽度&#xff0c;使用该属性是设置一个最小…

width和min-width的区别和差异性比较

1、正常情况下&#xff1a; width :给块级元素/行内块 元素设置固定的宽度&#xff0c;或者固定百分比的宽度。 min-width: 当盒子内部元素宽度小于 min-width的值时&#xff0c;盒子宽度为 min-width的值&#xff0c;当盒子内容宽度大于 min-width的值时&#xff0c;盒子随着…

【NOIP2013提高组】华容道

题目背景 NOIP2013 提高组 Day2 试题。 题目描述 小 B 最近迷上了华容道&#xff0c;可是他总是要花很长的时间才能完成一次。于是&#xff0c;他想到用编程来完成华容道&#xff1a;给定一种局面&#xff0c;华容道是否根本就无法完成&#xff0c;如果能完成&#xff0c;最…

【NOIP2013提高组】花匠

题目背景 NOIP2013 提高组 Day2 试题。 题目描述 花匠栋栋种了一排花&#xff0c;每株花都有自己的高度。花儿越长越大&#xff0c;也越来越挤。栋栋决定把这排中的一部分花移走&#xff0c;将剩下的留在原地&#xff0c;使得剩下的花能有空间长大&#xff0c;同时&#xff…

【NOIP2013提高组】积木大赛

题目背景 NOIP2013 提高组 Day2 试题 题目描述 春春幼儿园举办了一年一度的“积木大赛”。今年比赛的内容是搭建一座宽度为 n 的大厦&#xff0c;大厦可以看成由 n 块宽度为 1 的积木组成&#xff0c;第 i 块积木的最终高度需要是 hi。 在搭建开始之前&#xff0c;没有任何…

7.15 NOIP 2013

NOIP 2013 DAY 1 DAY1 T1 转圈游戏 快速幂模板 #include<bits/stdc.h> using namespace std; int n,m,k,x; long long ans; long long cmd(long long a,long long b){long long sum1;for(;a;a>>1){if(a&1){sumsum*b%n;}bb*b%n; } return sum; } int main(…

noip2013 day2

一道纯模拟就可以过&#xff08;水水水&#xff09;。 考试时本蒟蒻甚至写了个线段树&#xff0c;然后发现其实不如直接模拟。 模拟思路&#xff1a; 从1到n枚举每个最长的不为0的序列&#xff0c;每次每个数减去其中剩余的最小值&#xff0c;答案加上这个最小值&#xff0c…

noip2013

D1&#xff1a; T1&#xff1a;快速幂 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cstdlib> #include<cmath> #define LL long long using namespace std; LL n,m,k,x; inline LL quickpow(LL…

解题报告:NOIP2013 车站分级(拓扑序递推求解差分约束、建图优化O(n+m)) 超详细讲解

本题是2013年NOIP普及组的压轴题 差分约束裸题。 计算当前线路中最小的级别&#xff08;比较始发站和终点站&#xff09;。 整条线路中所有大于这个级别的都必须停靠 所有未停靠的站点的级别一定小于这个级别 也就是说所有未停靠的即为级别低&#xff0c;记为A 所有停靠的站点…

[NOIP2013]记数问题

[NOIP2013]记数问题 1.题目2.分析3.代码方法1&#xff1a;将每个数字的每一位单独算出方法2&#xff1a;转换为字符串再进行遍历 4.反思总结5.更新日志 1.题目 题目链接 题号&#xff1a;NC16538 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C…

ARMv8体系结构基础04:算术和移位指令

目录 1 数据处理指令概述 2 加法指令详解 2.1 ADD指令 2.1.1 ADD&#xff08;extended register&#xff09;指令编码分析 2.1.2 ADD&#xff08;extended register&#xff09;指令编码验证 2.1.3 ADD&#xff08;immediate&#xff09;指令编码分析 2.1.4 ADD&#xf…

8086CPU指令系统--汇编语言逻辑运算和移位操作指令

文章目录 一、逻辑运算指令1、逻辑‘与’指令 AND2、逻辑‘或’指令 OR3、逻辑“非”指令 NOT4、逻辑“异或” XOR5、测试指令TEST 二、移位指令1&#xff09;非循环移位1、算数左移SAL和逻辑左移SHL2、逻辑右移SHR3、算术右移SAR 2&#xff09;循环移位1、带CF的循环左移 RCL2…

arm64汇编学习-(3)算术与移位指令

arm64汇编学习-&#xff08;3&#xff09;算术与移位指令 1 数据处理指令1.1 check the C condition of adds, adc,cmp1.1.1 测试示例程序1.1.2 执行之前1.1.3 执行之后1.1.3.1 ldr和mov指令之后1.1.3.2 ads和adc指令之后1.1.3.3 cmp和adc指令之后 1.2 cmp和sbc指令的综合运用1…