How to check the screen size? For example,

if (дюйм_телефона <= 4){ (Действие какое-то); if (дюйм_телефона > 4 && дюйм_телефона <7) (Действие какое-то); else (Действие какое-то); 

Here is the leader, and by the size of the phones he should (FrameLayout) increase the height ...

enter image description here

How to check this in the code?

  • What does the length measure have to do with programming? - aleksandr barakin
  • If more than four inches, then I will increase the height of the hider ... That is, the application has a hider, and I have to dynamically increase and decrease it ... - DevOma

1 answer 1

Read about the support of various screen sizes in Android (in Russian).

In short: you make different layouts, create resources with folders corresponding to different ranges of screen sizes values-large , values-small , etc. You can create your own ranges using screen size classifiers

For example, values-w<n>dp ( values-w720dp , values-w1024dp etc.) defines the minimum available screen width.

And place the links to the layouts in the folders corresponding to the resolution and use the same names corresponding to the names of the resources.

Well, screen sizes in inches are as follows:

 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); //метод Activity int width=dm.widthPixels; int height=dm.heightPixels; int dens=dm.densityDpi; double wi=(double)width/(double)dens; double hi=(double)height/(double)dens; double x = Math.pow(wi,2); double y = Math.pow(hi,2); double screenInches = Math.sqrt(x+y); 
  • one
    Well, damn, there are normal people! Thank you very much!!! - DevOma
  • The error pops up on the second line ... Should these methods remain so without assignment to any variable? - DevOma
  • The dm in getMetrics is passed by reference and assigned there. Are you calling from Activity? - IEVGEN
  • Yes! All error disappeared. But when pressed, I wanted to make the toast pop up with the message "inch + inch"; Toast.makeText (getApplicationContext (), screenInches + "inch", Toast.LENGTH_SHORT) .show (); - DevOma