What\'s the proper way to get DisplayMetrics, i.e. get screen/display info such as density
or xdpi
?
I ask because I\'ve seen two ways of going
public DisplayMetrics getDisplayMetrics ()
Return the current display metrics that are in effect for this resource object. The returned object should be treated as read-only.
public void getMetrics (DisplayMetrics outMetrics)
Initialize a DisplayMetrics object from this display's data.
The difference is that the metrics returned by the Resources
method is the metrics for that particular Resources
object. You can always create a new Resources
instance with the constructor
Resources(AssetManager assets, DisplayMetrics metrics, Configuration config)
in which you can set any metrics you want, not necessarily the metrics you can get from the Display
instance returned by the method getDefaultDisplay()
.
That's the difference. It may not make a difference though in the values if you're using just the default resources and the default display.