Is it possible to set the Margins of a LinearLayout, programmatically but not with pixels, but dp?
The following method works for me for converting pixels to dp:
int pixelToDP(int pixel) { final float scale = RaditazApplication.getInstance().getResources().getDisplayMetrics().density; return (int) ((pixel * scale) + 0.5f); }