It is in pixels. But to be device independent, we need to set the value to dp.
So, in your code you can write a swicth case and based on the screen resolution that you can get from the device metrics, you can set the value accordingly as follows:
DisplayMetrics metrics = this.getResources().getDisplayMetrics(); if(metrics.density == 1) // else if(metrics.density == 2) // else if(metrics.density == 1.5) //
You can also change the px values โโto dp using the formula:
px = dp * (dpi / 160)
source share