Android DIP尺寸错误

发布于 2024-09-30 21:24:50 字数 310 浏览 0 评论 0原文

这个让我很困扰。我在忽略什么?我想要一个恰好一英寸宽的按钮,在任何密度的屏幕上。我在布局中声明它是这样的:

<Button  
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="160dip"
android:text="How wide?"
/>

我得到的是一个在所有屏幕上宽度正好是 7/8 英寸的按钮,而不是预期的 1 英寸。差异可能是按钮周围的边距或填充吗?如果是这样,如何将其设置为零?

This one is bedeviling me. What am I overlooking? I want a button exactly one inch wide, on any density screen. I declare it in the layout like this:

<Button  
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="160dip"
android:text="How wide?"
/>

What I get is a button that is exactly 7/8ths of an inch wide on all screens, not the expected 1 inch. Is the difference maybe the margin or padding around the button? If so, how to set that to zero?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

上课铃就是安魂曲 2024-10-07 21:24:50

这又如何呢?

android:layout_width="1in"

What about this ?

android:layout_width="1in"
心的憧憬 2024-10-07 21:24:50

倾角基于虚拟密度,而不是实际物理密度。例如,在 T-Mobile G1 上,设备的显示屏物理密度约为 180dpi,但我们将其视为 160dpi 显示屏。 Android 目前使用 3 个“密度桶”:120、160 和 240。每个设备都会使用最合适的。如果您想要精确的物理测量,请使用英寸、毫米等物理单位。

dip are based on virtual densities, not actual physical densities. For instance, on a T-Mobile G1, the device's display physical density is around 180dpi, but we treat it as a 160dpi display. Android currently uses 3 "density buckets," 120, 160 and 240. Each device uses whatever is most appropriate. If you want accurate physical measurements, use physical units like in, mm, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文