android - 如何以编程方式设置 ConstraintLayout 的 XML 属性“layout_constrainedWidth”?
问题描述
解决方案
如果您想以constrainedWidth/Height
编程方式设置,那么您必须根据自己的意愿ConstraintLayout.LayoutParams
设置名为constrainedWidth或constrainedHeight的标志。
IE
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) myView.getLayoutParams(); // View for which we need to set constrainedWidth.
lp.constrainedWidth = true/false;
myView.setLayoutParams(lp);
约束宽度
如果设置了左右约束并且小部件尺寸不是固定尺寸,则指定水平尺寸是否受到约束。
默认情况下,如果一个小部件设置为
WRAP_CONTENT
,我们会将该维度视为一个固定维度,这意味着无论约束如何,维度都不会改变。将此属性设置为true 允许更改维度以遵守约束。
在这里查看。
推荐阅读
- java - 向用户显示他点击了哪个按钮
- php - 如果打开 php 文件,指示 Web 浏览器重定向到 localhost
- javascript - Array.includes() 返回未定义
- c++ - 如何检查两个矩阵是否相同?
- javascript - 模板文字中的数组映射在项目之间呈现额外的逗号
- node.js - firebase 统计在线用户并在全球计数器中更新
- selenium - 在使用 java 的 Selenium Webdriver 中,热点击“获取 adobe Flash Player”图标?
- wordpress - VPS 上 WordPress 的权限
- c - 在C编程中实现堆栈的push方法
- selenium - 我们可以使用appium android阅读移动设备上可用的pdf文件吗