How to get the screen height and width:
1 import android.view.Display; 2 import android.view.WindowManager; 3 WindowManager windowManager = getWindowManager(); 4 Display display = windowManager.getDefaultDisplay(); 5 if(display.getWidth()==480 && display.getHeight()== 272 || 6 display.getWidth()==272 && display.getHeight()==480){ 7 mDirAdapter = new DirAdapter(this, 110, 120); 8 }else{ 9 mDirAdapter = new DirAdapter(this, 190, 200);10 }
In fact, the screen parameters can also be obtained in the view.
The Code is as follows:
1 // method 2 int H = This. getcontext (). getresources (). getdisplaymetrics (). heightpixels; 3 int W = This. getcontext (). getresources (). getdisplaymetrics (). widthpixels; 4 log. V ("######## H #######", String. valueof (h); 5 6 7 // method 2 8 windowmanager WM = (windowmanager) This. getcontext ()
. Getsystemservice (context. window_service); 9 display = WM. getdefadisplay display (); 10 int H1 = display. getheight (); 11 int W1 = display. getwidth ();
How to Set the control size in code
1 private Button mbtn;2 mbtn = (Button) findViewById(R.id.btn_test); 3 LayoutParams lp; 4 lp=mbtn.getLayoutParams();5 lp.width=100;6 lp.height=200; 7 mbtn.setLayoutParams(lp);
How to set the page size in the Code:
1 display = getwindowmanager (). getdefadisplay display (); // for obtaining screen width and height, 2 window = getwindow (); 3 layoutparams windowlayoutparams = Window. getattributes (); // obtain the current parameter value in the dialog box. 4. windowlayoutparams. width = (INT) (display. getwidth () * 0.7); // set the width to 0.95 of the screen. height = (INT) (display. getheight () * 0.1); // set the height to 0.66 windowlayoutparams of the screen. alpha = 0.5f ;//Set transparency
Obtain the screen height and width, and set the control size in the code.