我有一个Linearlayout
将一些视图组合在一起的习惯。我希望这Linearlayout
是wrap_content
为了高度。我尝试像这样在 custrucor 中添加布局参数
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
setLayoutParams(params);
但它没有效果。高度还在match_parent
。我还尝试onMeasure
根据这样的孩子的身高来计算身高
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
measureChildren(widthMeasureSpec,heightMeasureSpec);
int size = 0;
for(int i = 0; i <getChildCount();i++) {
size += getChildAt(i).getMeasuredHeight();
}
int height = resolveSize(size,heightMeasureSpec);
setMeasuredDimension(widthMeasureSpec,height);
}
它也没有任何作用。那么问题出在哪里?