Is it possible to set the Margins of a LinearLayout, programmatically but not with pixels, but dp?
You can use DisplayMetrics and determine the screen density. Something like this:
int dpValue = 5; // margin in dips float d = context.getResources().getDisplayMetrics().density; int margin = (int)(dpValue * d); // margin in pixels
As I remember it's better to use flooring for offsets and rounding for widths.
2.1m questions
2.1m answers
60 comments
57.0k users