Welcome 微信登录

首页 / 操作系统 / Linux / Android动态设置margins

拿TableLayout举例TableRow.LayoutParams p = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);   p.setMargins(2, 2, 2, 2); //left,top,right,bottomTableRow tr1 = (TableRow) findViewById(R.id.tr1);tr1.addView(yourview,p);----------------------------------------每一种Layout都有自己的LayoutParams再用Layout添加view的时候 只需要调用addView(view,layoutParams);这个重载方法就可以动态设定在xml中设置的很多属性