Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Android 中以编程方式更改作为 ConstraintLayout 子视图的约束?我找不到任何有用的文档。我什至找不到源代码或 API 文档。
在视图上设置的约束定义在ConstraintLayout.LayoutParams- 您可以获取视图的布局参数 ( View.getLayoutParams()),将其中的字段设置为您想要的内容并View.setLayoutParams()使用修改后的参数进行调用。
ConstraintLayout.LayoutParams
View.getLayoutParams()
View.setLayoutParams()
这会起作用,但是是的,等待官方文档可能会更好:)
更新:在发布 alpha 8 中有ConstraintSet
Alpha 8 发行说明
示例链接