Android mobile phone Resolution Test Program

Source: Internet
Author: User

TheProgramYou can test the resolution of a personal mobile phone device, which DPI level is used for development reference.

Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <textview Android: id = "@ + ID/screensize" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/screensize"/> <edittext Android: id = "@ + ID/size" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: inputtype = "numberdecimal"/> <buttonandroid: id = "@ + ID/submit" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/submit"/> <edittext Android: id = "@ + ID/showwidth" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: inputtype = "text" Android: editable = "false"/> <edittextandroid: Id = "@ + ID/showdpi" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: inputtype = "text" Android: editable = "false"/> </linearlayout>

String. xml

 
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello world, androiddpi! </String> <string name = "app_name"> androiddpi </string> <string name = "screensize"> enter the screen size of the device: </string> <string name = "Submit"> OK </string> </resources>

JavaCode:

Package COM. shine. android; import android. app. activity; import android. OS. bundle; import android. util. displaymetrics; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. edittext; public class androiddpi extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); Final edittext size = (edittext) findviewbyid (R. id. size); Final edittext showwidth = (edittext) findviewbyid (R. id. showwidth); Final edittext showdpi = (edittext) findviewbyid (R. id. showdpi); button submit = (button) findviewbyid (R. id. submit); Submit. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {If (size. length () = 0) {size. settext ("Enter the size of the screen");} else {displaymetrics dm = new displaymetrics (); getwindowmanager (). getdefadisplay display (). getmetrics (DM); int width = DM. widthpixels; int Height = DM. heightpixels; float sizeint = float. parsefloat (size. gettext (). tostring (); showwidth. settext ("cell phone screen resolution:" + width + "*" + height); double DPI = math. SQRT (height * height + width * width)/sizeint; string dpitype = ""; if (DPI> 320) {dpitype = "belongs to xhdpi ";} else if (DPI> 240) {dpitype = "hdhdpi";} else if (DPI> 160) {dpitype = "mdmdpi";} else if (DPI> 120) {dpitype = "ldpi";} showdpi. settext ("cell phone DPI:" + DPI + "," + dpitype );}}});}}

Display result:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.