2

I have a number of different layouts for different display sizes (see screen shot). Is it possible to determine programmatically, at runtime, which was used?

res

Edit: Suggestion was made to use this:

DisplayMetrics displayMetrics = new DisplayMetrics();
float density = displayMetrics.density;

This returns 0 for 3 devices: Samsung T530NU, ASUS Nexus 7, Droid Maxx
This code:

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int densityDpi = (int)(metrics.density * 160f);

returns the following:

Samsung T530NU: 160  
ASUS Nexus 7: 320  
Droid Maxx: 320 

Edit 2: I implemented something simlar to @Selvin's suggestion:

Create these folders in res:

values-large-land  
values-med-land  
values-small-land  
values-xlarge-land  
values-large-port  
values-med-port  
values-small-port  
values-xlarge-port

Each folder contains a file called strings.xml
Each strings.xml contains a string called device_size:

<string name="device_size">small-land</string>

with the value changing with the folder. For the default strings.xml file in the values folder, I assign this:

<string name="device_size">unknown</string>

Then you can refer to the string:

String device_size = getResources().getString(R.string.device_size);

This returns:

Samsung T530NU: xlarge-land    
ASUS Nexus 7: large-land  
Droid Maxx: unknown 

I'm not sure why the unknown on the Droid Maxx.

Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139

1 Answers1

1

There is not any resource folder qualifier names as med !

You should use normal instead. For example :

values-normal-land
values-normal-port

for more information refer this link from google.

Providing Resources

Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50