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.
1.4m articles
1.4m replys
5 comments
57.0k users