写一个自定义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" />

成功

Android 约束布局 ConstrainLayout min max width相关推荐

  1. android 约束 布局_Android约束布局动画

    android 约束 布局 In this tutorial, we'll be implementing Constraint Layout Animations in our Android Ap ...

  2. android约束布局中 链,Android-ConstraintLayout(约束布局)-Chains链(链条布局,Nice)

    到Chains这个部分了.之前的新项目做得登录,注册,重置密码等暂时还没用到这种.不过后面可能随着新的设计可能会涉及到.所以赶紧过来看看先.新项目基本就打算全部用约束布局实现了.实际用了也会越来越熟悉 ...

  3. android横向多布局约束,Android约束布局中心水平对齐Textview和Imageview不工作

    参见英文答案 > Constraint Layout Vertical Align Center                                    6个 我希望我的textv ...

  4. Android 约束布局:ConstraintLayout GuidLine

    默认的约束布局.里面控件是居中的 可以使用参考线Guideline做参考 来画出来心仪的位置 这布局在渲染上面是没有什么东西的 就是运行到手机上Guideline 是啥也没有的 究其原因因为 源码的d ...

  5. android 约束布局的坑,android - 使用android约束布局2.0.0 Flow将项目放置一行 - 堆栈内存溢出...

    我的xml流程布局 android:id="@+id/fr_mail_viewer_attachments_flow" android:layout_width="0dp ...

  6. android 约束布局 兼容,app:layout_marginBottom与android约束布局不兼容

    有没有理由为什么以下layout_marginBottom不起作用? 但是,如果我在第二个视图上使用layout_marginTop,它确实可以正常工作 xmlns:android="htt ...

  7. android 布局圆形_Android约束布局–圆形定位

    android 布局圆形 In this tutorial, we'll be discussing a cool attribute present in Constraint Layout, na ...

  8. 约束布局ConstraintLayout

    文章目录 一,背景 二,控件优点 三,项目中引入 四,基本使用 4.1 相对位置 4.2 尺寸约束 4.3 宽高比 Ratio 4.4 百分比宽高 Percent 4.5 偏移量 bias 4.6 圆 ...

  9. android鸿洋布局,Android基础ConstrainLayout约束布局的介绍和使用

    写在前面:之前稍微复杂的设计实现,我们都可能会借助于嵌套实现,我们知道嵌套越多,性能就越低.而我们布局一般都是在xml里面进行实现,拖拽的话估计现在android开发者都不会去使用.为了提升开发者的可 ...

最新文章

  1. java停车管理系统中期检查_java毕业设计_springboot框架的停车场收费管理系统
  2. Ubuntu侧边任务栏自动隐藏
  3. 电脑开机老是显示explorer.exe文件损坏
  4. linux ftp登录命令_Linux使用pinky命令查询登录用户信息
  5. python继承 子类init_Python类继承:使用自己的和父的默认值和init方法进行动态子类初始化...
  6. 微软发话:Win10杀毒软件要优先选它
  7. 信息安全系统设计基础第九周学习总结
  8. 如何在大多数文字编辑器中(包括word和一些程序编辑器中)不要使用鼠标(即用快捷键)复制上一行到下一行
  9. oracle存储过程 --1
  10. 这个统一了238个机器学习模型R包的参考手册推荐给你
  11. oledb vc访问mdb数据库_一个通用数据库操作组件DBUtil(c#)、支持SqlServer、Oracle、Mysql、postgres、SQLITE...
  12. 关于T_SQL中声明变量类型的基础知识。
  13. oracle 九阴真精,《九阴真经》真的很强吗?其实它杂而不精,顶级高手都不愿意用...
  14. 深度学习图像识别笔记(二):红外图像
  15. O365(世纪互联)SharePoint 之使用列表库发布新闻
  16. sas sata ssd硬盘类型,硬盘接口
  17. 计算机网络整理(上)
  18. 波纹扩散特效(仿支付宝咻一咻功能)
  19. 汽车驾驶学习-驾驶技巧:图解如何安全停车的技巧
  20. 史上最全因果推断合集-12(因果推断在哈啰出行的实践探索)

热门文章

  1. 灾变来袭不用怕,华为云数据灾备解决方案为你排忧解难
  2. 高中计算机教室标语,高中教室的标语
  3. 绕开“死循环”:苹果不靠英特尔处理器也能主导市场
  4. 基于siege的压力测试
  5. 社区共建合作须知:合作者实现美好的故事
  6. 跳过密码打开zip压缩包,zip压缩包不能打印复制怎么办?
  7. 格式工厂这款免费的录屏工具竟然这么好用
  8. Derby的下载安装和使用,(和JAVA中使用Derby)
  9. 装机必备 Windows Mobile系统最“牛”软件
  10. 开源世界不是乌托邦,百度们正在创造新未来