I am working on a project in which I am drawing views on screen programmatically. I want set the LayoutParams
based on device density. The views should be drawn in large size in high end devices and small in low density devices. Is there any multiplier value which can be used for varying densities?
Asked
Active
Viewed 321 times
0

Vadim Kotov
- 8,084
- 8
- 48
- 62

Jas
- 3,207
- 2
- 15
- 45
-
Possible duplicate of [Drawing on Canvas issue in high end devices](http://stackoverflow.com/questions/37988804/drawing-on-canvas-issue-in-high-end-devices) – Dmitry Zaytsev Jun 27 '16 at 11:27
1 Answers
0
Check this answer https://stackoverflow.com/a/4766229/5476209 by this you can get if device is high or low or medium density screen resolution.
Also check this code if you want to make a generic code that work for most of all devices then go here http://www.androidwarriors.com/2016/01/how-to-find-different-devices-screen.html
Below is simplest code snippet that can get device density, it returns integer value
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenDensity = metrics.densityDpi;
0.75 - Low density, 1 - medium density , 1.5 - high density and 2.0 - extra high density
-
I want a generic code obviously. But I am confused about the multiplier value I should use to make it work in all devices. – Jas Jun 27 '16 at 11:41
-
1As per my knowlege you have to make your own method , you can create your own parameterized method by taking this returned integer value by above snippet and then use your logic @Jas – TapanHP Jun 27 '16 at 11:45
-
http://stackoverflow.com/questions/37988804/drawing-on-canvas-issue-in-high-end-devices .This is another question I posted last day. It contains the code snippet I am using. Please check that – Jas Jun 27 '16 at 11:48