문제

I'm having a gridview for which I determine the cell size like this (in the xml file):

 android:columnWidth="@dimen/gridview_cell_dimen"

As you can see I am getting the dp dimension from my dimens folders (values-ldpi, values-hdpi,...).

My question now is - how to determine the correct dp sizes? For ldpi I simply use 20dp in this case, which perfectly fits the size from my smartphone. What would be the correct forumla to see which size would be correctly suitable for bigger screen resolutions like mdpi, hdpi, xhdpi, xxdpi?

Is there a rule of thumb which says: "Increase the size by 120%?" for example? So that I can say that the best resolution for mdpi would be: 24dp ? and for hdpi: 28dp in my case?

Thanks in advance!

도움이 되었습니까?

해결책

using dp as the unit is independent of the density of the screen, so you can stick to one value for all screen sizes.

From the Documentation:

Density-independent pixel (dp) A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top