LinearLayout
의 높이가 wrap_content
으로 설정되고 자식의 결합 된 높이가 화면보다 큰 경우 일부 자식은 보이지 않습니다. 이 경우 모든 어린이가 보일 때까지 어린이를 삭제하고 싶습니다. 이 작업을 수행하는 효율적인 방법은 무엇입니까?LinearLayout이 너무 작아서 자식을 포함 할 수 없는지 확인하는 방법
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//when measuring with unspecified, the layout will be as large as it wants to be
super.onMeasure(UNSPECIFIED_SPEC, UNSPECIFIED_SPEC);
if (getOrientation() == VERTICAL){
wantedLength = getMeasuredHeight();
} else {
wantedLength = getMeasuredWidth();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getOrientation() == VERTICAL){
measuredLength = getMeasuredHeight();
} else {
measuredLength = getMeasuredWidth();
}
while (measuredLength < wantedLength){
//todo remove child
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getOrientation() == VERTICAL){
measuredLength = getMeasuredHeight();
} else {
measuredLength = getMeasuredWidth();
}
}
}
두 번 측정하지 않고 레이아웃이 너무 작 았는지 여부를 알 수있는 방법이 있습니까? 나는 문서에서 MEASURED_STATE_TOO_SMALL
을 찾았지만 그것을 사용하는 방법을 모른다. https://developer.android.com/reference/android/view/View.html#getMeasuredHeightAndState()
왜 모든 것을 보관하기 위해 'scrollview'를 사용하지 않습니까? 어쨌든'Display' 클래스로부터 디스플레이 크기를 얻을 수 있습니다. 그런 다음 항목의 총 크기를 계산하십시오. 다른 항목을 제거하십시오. –
스크롤하지 않고 1 화면에 정보를 표시하고 싶습니다. 아이들이 적합하지 않을 때 덜 중요한 것들은 제거 될 수 있습니다. –