To add margins directly to items (some items allow direct editing of margins), you can do:
LayoutParams lp = ((ViewGroup) something).getLayoutParams();
if( lp instanceof MarginLayoutParams )
{
((MarginLayoutParams) lp).topMargin = ...;
((MarginLayoutParams) lp).leftMargin = ...;
//... etc
}
else
Log.e("MyApp", "Attempted to set the margins on a class that doesn't support margins: "+something.getClass().getName() );
...this works without needing to know about / edit the surrounding layout. Note the "instanceof" check in case you try and run this against something that doesn't support margins.