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>
本文详细解释了Android中setLayoutParams方法的作用及其用法。该方法用于设置View在其父容器中的布局参数,通过实例展示了如何利用LayoutParams指定View的位置及大小。

737

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



