Basically I have this inside XML, but I have to recreate it inside a code. How do I do it?
Solved here.
Extract:
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); float dp = 20f; float fpixels = metrics.density * dp; int pixels = (int) (fpixels + 0.5f);