setLayoutParams()是给其父控件看的
These supply parameters to the parent of this view specifying how it
should be arranged
其实这也好理解:只有父类可以改变子View的位置布局.而不是说子View可以随意按照自己的想法摆放自己的位置,而不受父控件控制 。
例子:
RelativeLayout.LayoutParams layoutParams
// =new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
// layoutParams.setMargins(280, 0, 0, 0);
// mTextView.setLayoutParams(layoutParams);
<span style="font-size:18px;">RelativeLayout.LayoutParams layoutParams=
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mTextView.setLayoutParams(layoutParams);
</span>