How to get the screen size of a mobile phone in Android

Source: Internet
Author: User
  1. Public


     
    Class


    Testactivity extends activity {

  2. Private


    Textview TV;

  3. Private


    Button BTN;

  4. // Get the mobile phone number
    Screen Resolution class


  5. Private


    Displaymetrics DM;

  6. Public


     
    Void


    Oncreate (bundle savedinstancestate ){
  7. Super. oncreate (savedinstancestate );
  8. SetContentView (R. layout. main );
  9. TV = (TextView) findViewById (R. id. TV );
  10. Btn = (Button) findViewById (R. id. btnOK );
  11. Btn. setOnClickListener (
    New


    View. OnClickListener (){

  12. Public


     
    Void


    OnClick (View v ){
  13. Dm =
    New


    Displaymetrics ();
  14. Getwindowmanager (). getdefaultdisplay (). getmetrics (DM );

  15. // Obtain the mobile phone number
    In pixels.

  16. String strpm =
    "Mobile Phone
    Screen Resolution :"

    + DM. widthpixels +
    "*"

    + DM. heightpixels;
  17. TV. settext (strpm );
  18. }
  19. });
  20. }
  21. }
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.