英文:
Exactly same size for all screens physically in Android
问题
如何可能使任何物体的尺寸在所有屏幕上在物理上保持相同大小?
答案1
得分: 0
从安卓开发者文档中:
> 为了在不同密度的屏幕上保持UI的可见大小,您必须使用密度无关像素(dp)作为您的测量单位来设计UI。一个dp是一个虚拟像素单位,大致相当于中密度屏幕(160dpi;“基准”密度)上的一个像素。Android会将这个值转换为其他每个密度的适当像素数量。
> 例如,考虑图1中的两台设备。如果您定义一个视图宽度为“100px”,它在左侧的设备上会显得更大。因此,您必须改为使用“100dp”来确保它在两个屏幕上显示相同的大小。
因此,您想要实现的目标可以通过将对象的高度和宽度属性的单位设置为dp
来实现。
英文:
From the android developer's documentation:
> To preserve the visible size of your UI on screens with different
> densities, you must design your UI using density-independent pixels
> (dp) as your unit of measurement. One dp is a virtual pixel unit
> that's roughly equal to one pixel on a medium-density screen (160dpi;
> the "baseline" density). Android translates this value to the
> appropriate number of real pixels for each other density.
>
> For example, consider the two devices in figure 1. If you were to
> define a view to be "100px" wide, it will appear much larger on the
> device on the left. So you must instead use "100dp" to ensure it
> appears the same size on both screens.
So, what you are trying to achieve is possible using dp
as the unit for the height and width properties of the object.
专注分享java语言的经验与见解,让所有开发者获益!
评论