时间:2022-03-19 10:48:02 | 栏目:Android代码 | 点击:次
LayoutParams主要保存了一个View的布局参数,因此可以使用LayoutParams来改变布局参数从而达到View位置的效果,一般在自定义View的时候使用。
LinearLayout.LayoutParams layoutParams=(LinearLayout.LayoutParams)getLayoutParams(); layoutParams.leftMargin=getLeft()+offsetX; layoutParams.topMargin=getTop()+offsetY; setLayoutParams(layoutParams)
RelativeLayout.LayoutParams layoutParams=(RelativeLayout.LayoutParams)getLayoutParams(); layoutParams.leftMargin=getLeft()+offsetX; layoutParams.topMargin=getTop()+offsetY; setLayoutParams(layoutParams)
ViewGroup.MarginLayoutParams layoutParams=(ViewGroup.MarginLayoutParams)getLayoutParams(); layoutParams.leftMargin=getLeft()+offsetX; layoutParams.topMargin=getTop()+offsetY; setLayoutParams(layoutParams);
View line = null; LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); layoutParams.leftMargin = 10; line = new View(mContext); line.setBackgroundResource(R.color.color_tie_bg); addView(line, layoutParams);
Window win = getWindow(); WindowManager.LayoutParams lp = win.getAttributes(); lp.height = DensityUtil.dip2px(mContext, 185); lp.width = DensityUtil.dip2px(mContext, 280); win.setAttributes(lp);
以上是在开发过程中用到的一些LayoutParams相关的内容,后期会不断补充。