I\'m trying to nest a RelativeLayout
inside of a LinearLayout
, and give the RelativeLayout
a margin that spaces it\'s edges away from the
Edit:
You are using MarginLayoutParams instead of LinearLayoutParams. NOTE: if you set LayoutParams on a layout container, you will need to use the parent's type.
So if you have a LinearLayout that contains a RelativeLayout, you need to set LinearLayout.LayoutParams on the RelativeLayout.
// NOT WORKING: LinearLayout.LayoutParams params = (LayoutParams) getLayoutParams();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int tbm = AllConversationsActivity.topAndBottomMargin;
int lrm = AllConversationsActivity.leftAndRightMargin;
params.setMargins(tbm, lrm, tbm, lrm);
setLayoutParams(params);