您的位置:首页 > 移动开发 > Android开发

android 代码布局 Margin 与 padding的区别

2011-09-14 20:36 465 查看
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 ) ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: