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 ) ;
本文介绍了在Android应用开发中如何使用LinearLayout.LayoutParams来设置控件的布局参数,特别是如何通过setMargins方法调整控件间的间距,以及控件内部资源与边框的距离(setPadding)的区别。
661

被折叠的 条评论
为什么被折叠?



