0

I thought I was successful in adjusting for different screen sizes(I was using the eclipse emulators and creating different screen sizes to test my app) but when I test my app on actual devices the result of my app varies. for example for a large screen size I set my emulator to a Nexus S and it will work and look fine, but then I try on an Alcatel One Touch Fierce(real device) which is still considered a large screen size the app play is just a little bit off, then I play it on another device which is also considered a large screen size the app will play just like the emulator. So i guess mt question is why? a samble of how I'm checking for different screen sizes is below:

    DisplayMetrics displayMetrics = new DisplayMetrics();
     getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
     switch(displayMetrics.densityDpi)
     { 
     case DisplayMetrics.DENSITY_LOW: 
        // layout for small sized devices.

        break; 
     case DisplayMetrics.DENSITY_MEDIUM: 
        // layout for medium-sized devices.


        break; 
     case DisplayMetrics.DENSITY_HIGH: 
                   // layout for large devices.

        break; 

     case DisplayMetrics.DENSITY_XHIGH:

                     // layout for really large devices.
        break; 
tshepang
  • 12,111
  • 21
  • 91
  • 136
Roy Sorvari
  • 50
  • 1
  • 1
  • 6

2 Answers2

1

Before your case statement, try to print the density value like this:

Log.i("Sushil", "displaymetrics.densityDpi : " + displaymetrics.densityDpi);

And check if it matches with any of your defined case statement. Else add new case statements, it should work. Few more defined cases are :

DisplayMetrics.DENSITY_TV
DisplayMetrics.DENSITY_XXHIGH

Hope this helps.

Sushil
  • 8,250
  • 3
  • 39
  • 71
  • ok for sure, but how many different sizes are there within any one of my already defined case statements? surely there is a more generalized way of dealing with the different sizes? – Roy Sorvari Mar 10 '14 at 04:00
  • @RoySorvari Yes. Normally we support it using different layouts. Still as their are so many android devices and comes in so many different density and resolutions defined by OEMs, its really difficult to set a standard which works for all. So, may need to hardcode few values. Also you can follow links below for standard process : http://stackoverflow.com/questions/12242111/application-skeleton-to-support-multiple-screen/12258061#12258061 http://developer.android.com/training/multiscreen/index.html – Sushil Mar 10 '14 at 04:04
1

i don't see any thing wrong with the outcomes. if you run an app designed on a phone emulator-----on a tablet, the layouts will not match.

you have to decide if you wanna support different screen sizes or not if you do, then you'd have to create diffrent layouts for different screen sizes and set the corresponding layout in the OnCreate method of your Activity.

here is how to check if the device is a tablet or a phone:

if(isTablet==true){
   setContentView(R.Layout.my_tablet_layout);
 }else{
   setContentView(R.Layout.my_phone_layout);
 }



public boolean IsTablet() {

    return (getApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;

}
kc ochibili
  • 3,103
  • 2
  • 25
  • 25
  • so you are saying that within my given cases there are even more different screen densities? if true then do i have to make a case to handle each different density? – Roy Sorvari Mar 10 '14 at 04:05
  • your cases are seraching for screen density(pixesl per inch) not screen sizes. the galaxy s3 can have more density than a 7 inch tablet. to solve the problem of densities, you have to use dp in your xml instead of px. that way the layout wont be crammed in a high density device. example: use this `android:layout_height="5dp"` not this `android:layout_height="5px"` to solve the problem of screen sizes, you have to use the answer above. and dont forget to never use px in your layouts. – kc ochibili Mar 10 '14 at 13:49