Simple code snippet to Set Margin on scal Metrics of devices dynamically.
MarginLayoutParams marginParams = new MarginLayoutParams(
frameLayout.getLayoutParams());
final float scale = getResources().getDisplayMetrics().density;
leftMargin = (int) (leftMargin * scale );
marginParams.setMargins(leftMargin, topMargin, 0, 0);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
marginParams);
layoutParams.gravity = Gravity.NO_GRAVITY; // This is the new line
frameLayout.setLayoutParams(layoutParams);
Happy Codding
No comments:
Post a Comment