方式一:
//注意需要先将view添加进父View,才能获取parmas
ll_point_group.addView(point);
//设置间距(点放进线性布局中,和父布局保持一致,)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(point.getLayoutParams());
params.weight =dp2px(TitleActivity.this,7) ;
params.height = dp2px(TitleActivity.this,7);
if (i==0){
point.setEnabled(true);//显示红色
}else {
point.setEnabled(false);//显示灰色
params.leftMargin = dp2px(TitleActivity.this,8);
}
// point.setLayoutParams(params);
ll_point_group.addView(point);
方式二:
// LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(dp2px(TitleActivity.this,7), dp2px(TitleActivity.this,7));
if (i==0){
point.setEnabled(true);//显示红色
}else {
point.setEnabled(false);//显示灰色
params.leftMargin = dp2px(TitleActivity.this,8);
}
// point.setLayoutParams(params2);
ll_point_group.addView(point);
本质没有什么区别,都是构建view,然后将其加入到父布局中