Set Margin on RecyclerView programmatically

前端 未结 4 763
旧巷少年郎
旧巷少年郎 2021-01-12 00:13

I need to set the top margin on a RecyclerView programmatically, but I get this exception:

java.lang.RuntimeException: Unable to resume activity java.lang.Cla

4条回答
  •  礼貌的吻别
    2021-01-12 01:00

    Try this out. You can refer to this for more info.

    ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(mRecyclerView.getLayoutParams());
    marginLayoutParams.setMargins(0, 10, 0, 10);
    mRecyclerView.setLayoutParams(marginLayoutParams);
    

提交回复
热议问题