Reputation: 742
Hi I want to change my layout top margin, but remain other margin parameters unchanged, my source is inside a fragment, if i use the code below, my other parameters will be set to zero
mainScreen = (RelativeLayout) v.findViewById(R.id.main_screen);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mainScreen.getLayoutParams();
params.setMargins(0, 390, 0, 0);
mainScreen.setLayoutParams(params);
Thanks.
Upvotes: 0
Views: 494
Reputation: 3845
You can use this just to set only top margin :
params.topMargin=10; //It will set value in pixel
Upvotes: 1
Reputation: 157467
just read the other margin from the LayoutParams
object you get form getLayoutParams()
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mainScreen.getLayoutParams();
params.setMargins(params.leftMargin, 390, params.rightMargin, params.bottomMargin);
Upvotes: 2