It inflate the view without the margin It inflate the view without the margin android android

It inflate the view without the margin


The last parameter of the inflate method is the parameter to which you add the inflated view. In your case it is null. Try this instead:

 View item = View.inflate(context, R.layout.item_layout, layout);


Try Padding the RelativeLayout instead if your margins apply to the outside.


You can add margin to layout which you inflated like below:

final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,                                                                                ViewGroup.LayoutParams.WRAP_CONTENT);         params.topMargin = 10;