LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) TextView.getLayoutParams(); //取控件textView当前的布局参数
linearParams.width = 40;// 控件的宽强制设成30
linearParams.height =40;// 控件的高强制设成20
TextView.setLayoutParams(linearParams);
/**
* 重设 view 的宽高
*/
public static void setViewLayoutParams(View view, int nWidth, int nHeight) {
ViewGroup.LayoutParams lp = view.getLayoutParams();
if (lp.height != nHeight || lp.width != nWidth) {
lp.width = nWidth;
lp.height = nHeight;
view.setLayoutParams(lp);
}
}
自动属性长度
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.MATCH_PARENT
控件的边距
RelativeLayout.LayoutParams linearParams2 =(RelativeLayout.LayoutParams) top2.getLayoutParams(); //取控件textView当前的布局参数
linearParams2.topMargin