android - ConstraintSet.connect() 中的边距参数是 px 还是 dp?
问题描述
val margin = 8
ConstraintSet().apply {
connect(anId, ConstraintSet.START, anotherId, ConstraintSet.START, margin)
}
应用为margin
像素还是依赖于密度的像素?
散布在网络上的各种文章和杜撰的知识似乎并不一致。我正在寻找官方文件或来源证据。
解决方案
该margin
参数应以像素为单位提供。
我最终追踪ConstraintSet.applyTo(ConstraintLayout)
到ConstraintSet.applyToInternal(ConstraintLayout)
,发现在这里, a 的每个孩子ConstraintLayout
都有其LayoutParams
复制并传递给ConstraintSet.Constraint.applyTo(LayoutParams)
。然后将所有参数(未经修改)从 复制ConstraintSet.Constraint
到 中LayoutParams
,然后将修改LayoutParams
后的分配回子项。我认为这是提供的保证金参数应遵循LayoutParams
规则的具体证据。
在 ConstraintSet.java 中
this.applyToInternal(constraintLayout); constraintLayout.setConstraintSet((ConstraintSet)null); }
applyToInternal(ConstraintLayout)
申报时
int count = constraintLayout.getChildCount(); //... LayoutParams param; for(int i = 0; i < count; ++i) { View view = constraintLayout.getChildAt(i); //... param = (LayoutParams)view.getLayoutParams(); constraint.applyTo(param); view.setLayoutParams(param); //... } //...
applyTo(LayoutParams)
申报时
//... param.leftMargin = this.leftMargin; param.rightMargin = this.rightMargin; param.topMargin = this.topMargin; param.bottomMargin = this.bottomMargin; //...
推荐阅读
- python - 显示特定学生以各自价格购买的水果
- android - 无需清单权限即可打开呼叫意图和短信意图
- ionic-framework - 在离子菜单中设置动态项目
- c - 删除使用 __attribute__((section)) 创建的部分
- reactjs - 序列化数据以响应提交发布请求
- symfony - Sylius 1.3 - “Sylius\Component\Addressing\Model\X”的类“App\Entity\X”子类不是有效的实体或映射的超类
- java - Java将int重载为long
- sass - Fontawesome 5+ 图标未显示
- arrays - 将具有 1 个有效位的 16 字节/字节数组转换/重新打包为具有 python3 中所有有效位的字节
- python - 在给定路径时搜索 S3 中的文件