gpt4 book ai didi

Android 将宽度设置为 ConstraintLayout.LayoutParams.MATCH_PARENT 给出 -1

转载 作者:行者123 更新时间:2023-12-05 00:15:36 24 4
gpt4 key购买 nike

我在创建弹出窗口时有此代码

val width = ConstraintLayout.LayoutParams.MATCH_PARENT

弹出窗口正在显示,并且具有所需的全宽度。但由于某些原因,宽度变量被分配为 -1,我使用该变量来填充弹出窗口中的其他内容,以便它们得到负宽度并且不会显示。当弹出窗口达到全宽时,为什么会返回 -1?

最佳答案

public static final int MATCH_PARENT Special value for the height orwidth requested by a View. MATCH_PARENT means that the view wants tobe as big as its parent, minus the parent's padding, if any.Introduced in API Level 8.

Constant Value: -1 (0xffffffff) (+)

要获取特定 View 的宽度,您可以执行以下操作:

int width = specificView.getWidth();

关于Android 将宽度设置为 ConstraintLayout.LayoutParams.MATCH_PARENT 给出 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65916740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com