Monday, May 26, 2014

Android Setting Layout Parameters Programmatically

This is how it's done:

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
params.setMargins(10, 0, 0, 0);

But the catch is, if you are adding these views programmatically in the first place, you will need to ensure that the above code runs only after the views have been added to the parent.

No comments:

Post a Comment