Android mobile phone screen size acquisition, android screen acquisition

Source: Internet
Author: User

Android mobile phone screen size acquisition, android screen acquisition

Package com. example. testactivity; import android. app. activity; import android. OS. bundle; import android. util. displayMetrics; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. textView; public class TextActivity extends Activity {private TextView TV; private Button btn; // class for obtaining mobile phone screen resolution private DisplayMetrics dm; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); TV = (TextView) findViewById (R. id. textView1); btn = (Button) findViewById (R. id. button1); btn. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// TODO Auto-generated method stub dm = new DisplayMetrics (); getWindowManager (). getdefadisplay display (). getMetrics (dm); // get the cell phone width and height String strPM = "cell phone resolution:" + dm. widthPixels + "*" + dm. heightPixels; TV. setText (strPM) ;}}) ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}

Effect

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.