美文网首页
代码动态设置布局参数

代码动态设置布局参数

作者: 逆流而shang | 来源:发表于2017-09-13 11:15 被阅读0次

一、如果控件已经在布局文件中声明,则在代码中直接用控件实例获取布局对象:

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);

相关文章

网友评论

      本文标题:代码动态设置布局参数

      本文链接:https://www.haomeiwen.com/subject/aeyksxtx.html