gpt4 book ai didi

android - PopupWindow 的大小以 px 或 dip 为单位?

转载 作者:行者123 更新时间:2023-11-29 16:05:06 24 4
gpt4 key购买 nike

来自 PopupWindow Docs :

public PopupWindow (int width, int height)

Added in API level 1 Create a new empty, non focusable popup window. The dimension of the window must be passed to this constructor.

The popup does not provide any background. This should be handled by the content view.

Parameters
width the popup's width
height the popup's height

问题 widthheight 是以像素 (px) 还是与密度无关的像素 (浸)?

奖励问题: PopupWindow 如何实现多屏支持?

最佳答案

宽度和高度参数以像素 (px) 为单位指定。如果要转换为与密度无关的像素 (dp),可以使用以下方法:

TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 65, getResources().getDisplayMetrics());

其中 65 替换为与密度无关的像素数。这将返回您可以提供给 PopupWindow 的像素数。

关于android - PopupWindow 的大小以 px 或 dip 为单位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19610044/

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