android - Determine at runtime which layout was used -
i have number of different layouts different display sizes (see screen shot). possible determine programmatically, @ runtime, used?
edit: suggestion made use this:
displaymetrics displaymetrics = new displaymetrics(); float density = displaymetrics.density;
this returns 0 3 devices: samsung t530nu, asus nexus 7, droid maxx
code:
displaymetrics metrics = context.getresources().getdisplaymetrics(); int densitydpi = (int)(metrics.density * 160f);
returns following:
samsung t530nu: 160 asus nexus 7: 320 droid maxx: 320
edit 2: implemented simlar @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 file called strings.xml
each strings.xml contains string called device_size:
<string name="device_size">small-land</string>
with value changing folder. default strings.xml file in values folder, assign this:
<string name="device_size">unknown</string>
then can refer 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 unknown on droid maxx.
there not resource folder qualifier names med
!
you should use normal
instead. example :
values-normal-land values-normal-port
for more information refer link google.
Comments
Post a Comment