Dp在Android中的应用
我对“dp”的用法有疑问Dp在Android中的应用,android,dpi,Android,Dpi,我对“dp”的用法有疑问 在哪种情况下可以使用dp?它是否仅用于任何控件,如ImageView和TextView,或者也可用于调整布局。 为了调整布局,我目前正在根据屏幕宽度和高度的百分比指定控件的宽度和高度。它可以用作指定宽度和高度的单位。。您可以将其用于所有视图…有关详细信息,请参阅 Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These
在哪种情况下可以使用dp?它是否仅用于任何控件,如ImageView和TextView,或者也可用于调整布局。
为了调整布局,我目前正在根据屏幕宽度和高度的百分比指定控件的宽度和高度。它可以用作指定宽度和高度的单位。。您可以将其用于所有视图…有关详细信息,请参阅
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp",
dip或dp的使用是为了使您的Android应用程序与多个屏幕密度和分辨率兼容。将有帮助。ohk但是dp可以用来指定填充,而不是用百分比来指定填充,例如.int width=display.getWidth();txtfourelcurrentkm.setPadding(0,0,(int)(宽度*0.005),0)。。我现在用这个@这是我想知道的。。我也试着这么做。。但是否建议使用屏幕宽度百分比或dp?@sankettt。。dp是前进的方向。。它特别支持多种分辨率和屏幕大小。谢谢。。但当我用它来填充时,图像会缩小,我会添加填充。@sankettt。。不要给图片固定宽度。。比如wrap_content,因为我对每个屏幕大小使用一个中等大小的图像,并根据dp指定宽度和高度,它根据各种屏幕的dpi上下缩放。我的问题是,我想实现像圆形一样放置的图像,所以我必须提供填充来实现,所以我应该用什么术语来指定填充,我尝试用dp来指定填充,但它变小了。