Assuming that view
contains a reference to the view for which you want to change the margins, you can set the bottom margin to 20 pixels with the following:
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 0, 20);
view.setLayoutParams(lp);
Note that this will change the bottom margin to 20 pixels and not 20dp. You will need to convert your 20dp value to pixels. Converting pixels to dp would be a good place to take a look at how that conversion can be done.
You may also need to change the height and width parameters on the constructor for LinearLayout.LayoutParams to fit you needs.
If the issue is getting a reference to the view, posting some code would be helpful.
Edit/Update
The code helped. I don't think that you are setting up access to the view you want. Here is another approach:
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// Find the adapter position of the first fully visible item
// May return RecyclerView.NO_POSITION that is not handled here.
firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition();
// Find the corresponding view holder for this position.
// MyViewHolder should already be defined (just don't know the name).
MyViewHolder vh = (MyViewHolder) mRecyclerView
.findViewHolderForAdapterPosition(firstVisibleItem);
// Get the layout parameters from the top-level item of this view.
// This could also be another view captured within the view holder.
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) vh.itemView.getLayoutParams();
// Make our changes and set them.
lp.setMargins(0, 0, 0, 50);
vh.itemView.setLayoutParams(lp);
}
});