一、如果控件已经在布局文件中声明,则在代码中直接用控件实例获取布局对象:
LinearLayout.LayoutParams layoutParams = mTextView.getLayoutParams();
然后再去设置相关设置(margins,width,height, gravity).
二、若是new出来的控件,则:
TextView textView =newTextView(this);
LinearLayout.LayoutParams layoutParams =newLinearLayout.LayoutParams(300,900);
layoutParams.setMargins(22,90,88,22);
layoutParams.gravity= Gravity.CENTER;
textView.setPadding(30,33,22,11);
textView.setLayoutParams(layoutParams);
网友评论