Example of obtaining mobile phone screen size (displaymetrics application) based on Android programming

This paper describes the method of Android to obtain the screen size of mobile phone. Share with you for your reference, as follows:

Here we mainly use three objects: textview, button and displaymetrics. Displaymetrics is the key class to obtain the screen size of the mobile phone. This example is very simple. When we click a button, an event is triggered to display the wide and high resolution of the mobile phone screen in textview

Take a look at the renderings:

Before the button is triggered:

After the button is triggered:

Where we are in res - > layout - > values - > string XML adds two lines as follows:

The specific codes are as follows:

The layout file main The XML code is as follows:

Finally, our main class displaymetricsdemo Java, the code is as follows:

This example is relatively simple. The core is a few lines of code in onclick

For more Android related content, readers who are interested can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android view skills, summary of activity operation skills of Android programming, summary of skills of operating SQLite database for Android, summary of skills of operating JSON format data for Android, summary of operating skills of Android database Summary of Android file operation skills, summary of SD card operation methods for Android programming development, summary of Android resource operation skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>