首页 > 技术文章 > 动态设置视图大小

wutianlong 2017-05-25 16:17 原文

private void setLinearLayoutParams(View imageView) {
if (mScreenSize == 0 )
mScreenSize = getScreenSize();

int width = ViewGroup.LayoutParams.MATCH_PARENT;

int height = 0;
if (mScreenSize <= 7)
height = LayoutConstants.sVerVideoImgHeight + 165;
else
height = LayoutConstants.sVerVideoImgHeight + 115;

ViewGroup.LayoutParams params = imageView.getLayoutParams();
if (params == null) {
params = new ViewGroup.LayoutParams(width, height);
imageView.setLayoutParams(params);
} else {
params.width = width;
params.height = height;
}
}



动态根据weight添加
LinearLayout.LayoutParams paramsItemView = new LinearLayout.LayoutParams(
0,
ViewGroup.LayoutParams.WRAP_CONTENT, 1);
LinearLayout.addView(convertView,paramsItemView);



推荐阅读