如何设置保证金虚增的LinearLayout动态? [英] How to set margin in inflated linearlayout dynamically?
本文介绍了如何设置保证金虚增的LinearLayout动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在的LinearLayout
动态使用这种code增加了一个的LinearLayout
。
的LinearLayout根=(的LinearLayout)findViewById(R.id.root);
查看孩子= inflater.inflate(R.layout.childrow,NULL);
root.addView(儿童,指数++);
我要在childview增加下边距。我可以这样做动态?
解决方案
查看孩子= inflater.inflate(R.layout.childrow,NULL);
LinearLayout.LayoutParams PARAMS =(LinearLayout.LayoutParams)child.getLayoutParams();
params.setMargins(LEFTMARGIN,TOPMARGIN,rightMargin,bottomMargin);
child.setLayoutParams(PARAMS);
root.addView(儿童,指数++);
I have added a linearlayout
in a linearlayout
dynamically using this code.
LinearLayout root = (LinearLayout) findViewById(R.id.root);
View child = inflater.inflate(R.layout.childrow, null);
root.addView(child , index++);
I want to add bottom margin in childview. Can I do this dynamically?
解决方案
View child = inflater.inflate(R.layout.childrow, null);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) child.getLayoutParams();
params.setMargins(leftMargin, topMargin,rightMargin, bottomMargin);
child.setLayoutParams(params);
root.addView(child , index++);
这篇关于如何设置保证金虚增的LinearLayout动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文