본문 바로가기

안드로이드/고급

안드로이드 자식뷰 강제 높이 구하기


private int getChildHeight(ViewGroup parentView) {
final int measureSpecW = View.MeasureSpec.makeMeasureSpec(parentView.getWidth(), View.MeasureSpec.EXACTLY);
final int measureSpecH = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
for (int i = 0; i < parentView.getChildCount(); i++) {
View childView = parentView.getChildAt(i);
ViewGroup.LayoutParams p = (ViewGroup.LayoutParams) childView.getLayoutParams();
int lpHeight = p.height;

int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
} else {
childHeightSpec = measureSpecH;
}
childView.measure(measureSpecW, childHeightSpec);
totalHeight += childView.getMeasuredHeight();
}
return totalHeight;
}



'안드로이드 > 고급' 카테고리의 다른 글

안드로이드 크롭 구현 자료  (0) 2017.10.04
안드로이드 갤러리 구현 자료  (0) 2017.10.04
annotation 어노테이션  (0) 2017.10.04
카카오 로그인에서 hash 구하기  (0) 2017.10.04
canvas 프로그래스  (0) 2017.10.04