Android programmatically distinguish between ldpi, mdpi, etc
I have multiple assets 开发者_如何学Pythonand multiple layouts, but there are some parts of this app where I set width and height dip values within the java code. How do I distinguish between screen sizes here?
context.getResources().getDisplayMetrics().density * sizeInDips
will give you the size in pixels on the current device.
Edit: If you want conditional values based on the configuration, you can do things like:
res/values/dimens.xml:
<resources>
<dimen name="foo">8dip</dimen>
</resources>
res/values-xlarge/dimens.xml:
<resources>
<dimen name="foo">16dip</dimen>
</resources>
These values can change based on any of the available resource configuration specifiers.
This will help:
- xlarge screens are at least 960dp x 720dp
- large screens are at least 640dp x 480dp
- normal screens are at least 470dp x 320dp
- small screens are at least 426dp x 320dp
AND
From http://developer.android.com/guide/practices/screens_support.html
精彩评论