Android动态设置margins

2014-11-24 11:39:41 来源: 作者: 浏览: 1

拿TableLayout举例


TableRow.LayoutParams p = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);


p.setMargins(2, 2, 2, 2); //left,top,right,bottom


TableRow tr1 = (TableRow) findViewById(R.id.tr1);


tr1.addView(yourview,p);


----------------------------------------


每一种Layout都有自己的LayoutParams


再用Layout添加view的时候 只需要调用addView(view,layoutParams);这个重载方法就可以动态设定在xml中设置的很多属性


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: