# # Screen fit # #加载不同分辨率的图片是根据手机的像素来加载不同分辨率文件夹下的图片. > First in the main screen to send: the*720(resolution and phone screen size independent), follow the principle: no absolutelayout (absolute layout), multi-use relative layout &linear layout (weight), with DP, without PX> > Late Development, test on different resolution screens (480* -,1920x1080* the), if there is no big problem (affecting normal use), you can go online> > What if the problem is detected later?picture adaptation is not very common, for different resolutions of the phone to do different pictures. -layout adaptation is not very commonly used, layout-800x480Specially adapted 480*800 layout file for the screen. -size fit DP and PX Relationship: DP= px/device density (pixel px is the real screen unit)floatDensity =getresources (). Getdisplaymetrics (). density; System. out. println ("Device density:"+density); the* -(0.75),480* the(1),480* -(1.5), the*720(2) under the Values folder, create a dimens.xml file that values-1280x720 folder to create a Dimens.xml file, these 2 dimens.xml respectively write <dimen name="Textview_width">320dp</dimen>used to load different sizes on different screens. -weight adaptation weights only have linear layouts. Android:weightsum="3", the parent layout has a total of 3 weights, and a total of less than 3 sub-layouts is left blank. -code adaptation get screen height, dynamically calculate control sizeintwidth = Getwindowmanager (). Getdefaultdisplay (). GetWidth ();//width of the screen intHeight = Getwindowmanager (). Getdefaultdisplay (). GetHeight ();//the height of the screenTextView TV1=(TextView) Findviewbyid (r.id.tv_1); TextView TV2=(TextView) Findviewbyid (r.id.tv_2); Layoutparamsparams=NewLayoutparams (Width/3, (int) (Height *0.2)); Tv1.setlayoutparams (params);//to dynamically set the size of a controlTv2.setlayoutparams (params);
android127 zhihuibeijing Screen Fit