LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 20, 10, 10);
//Margin是父控件中子空间之间的距离,一般设置在LayoutParams中,一般控件方法中没有setMargin,控件方法中的setPadding是设置控件中资源距离控件边框
//之间的距离,如果控件只设置了background则padding没有效果,如果padding值过大,会使控件扩大。
ImageButton whetherSelected = new ImageButton( SettingsActivity.this ) ;
whetherSelected.setLayoutParams(lp);
layout.addView( itemTextView , new layoutParams() ) ;
//上两句可直接写成
layout.addView( itemTextView , new layoutParams(),lp ) ;