setMargins method is not working on custom ViewGroup

北城余情 提交于 2019-12-06 04:25:50

The mistake I was doing is, in my code I have declared an instance of ViewGroup.MarginLayoutParams layoutParams1 and I am passing the same instance in linearLayout.addView(vg1,layoutParams1) but the method addView() accepts View as first argument and an instance of LayoutParams as second.

So I think that was the problem (not fully sure). So I changed my code to

LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,200);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!