Android is very often used to obtain the screen size. For example, if you want to write a program and make a program with strong versatility, the screen is very applicable. Generally, the layout is defined based on the screen length and width, so I will summarize this to facilitate future reference when I forget it. In addition, sometimes writing a program requires no title. You can set a screen without title in the program! Reprinted please indicate the source:
Http://blog.csdn.net/wdaming1986/article/details/6769821
Program:
The Code illustrates all truths:
1. mainactivity. Java code:
Package com.cn. daming; import android. app. activity; import android. OS. bundle; import android. util. displaymetrics; import android. view. window; import android. view. windowmanager; import android. widget. textview; public class mainactivity extends activity {private textview mtextview; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // set it to the Untitled requestwindowfeature (window. feature_no_title); // set it to full screen mode getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); setcontentview (R. layout. main); // defines the displaymetrics object displaymetrics dm = new displaymetrics (); // obtains the window attribute getwindowmanager (). getdefadisplay display (). getmetrics (DM); // window width int screenwidth = DM. widthpixels; // The window height int screenheight = DM. heightpixels; mtextview = (textview) findviewbyid (R. id. text_view); mtextview. settext ("screen width:" + screenwidth + "\ n screen height:" + screenheight );}}
Ii. Main. xml layout file code:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:id="@+id/text_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical|center_horizontal" android:gravity="center" android:text="@string/hello" android:textSize="18pt" /></LinearLayout>