Is it possible to set the Margins of a LinearLayout, programmatically but not with pixels, but dp?
You can convert dp to px, for example convert 5dp to px:
Resources r = mContext.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());