Relative Layout ignoring setMargin()

让人想犯罪 __ 提交于 2019-12-03 22:38:16
Entreco

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!