设置宽度以匹配 ConstraintLayout 中的约束 [英] Set width to match constraints in ConstraintLayout

查看:31
本文介绍了设置宽度以匹配 ConstraintLayout 中的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将视图的左侧和右侧限制到其父视图的边距并使其填充分配的空间.但是,将宽度设置为 match_parentwrap_content 似乎会产生相同的结果.

I would like to constrain a View's left and right sides to it's parent view's margins and make it fill the allotted space. However, setting width to either match_parent or wrap_content appears to produce the same result.

是否有与 match_constraints 等效的东西(相对于 match_parent 和 wrap_content)?match_parentwrap_content 会影响布局还是在新的约束布局中被忽略?

Is there something equivalent to match_constraints (as opposed to match_parent and wrap_content)? Do match_parent and wrap_content affect the layout or are they ignored in the new constraint layout?

推荐答案

match_parent 不被支持,所以使用 android:layout_width=0dp".使用 0dp,您可以将约束视为可扩展的"而不是填充剩下的".

match_parent is not supported, so use android:layout_width="0dp". With 0dp, you can think of your constraints as 'scalable' rather than 'filling whats left'.

此外,0dp 可以由位置定义,其中 match_parent 依赖于它的父级位置(x、y 和宽度、高度)

Also, 0dp can be defined by a position, where match_parent relies on it's parent for it's position (x,y and width, height)

这篇关于设置宽度以匹配 ConstraintLayout 中的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆