0
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();
}
}
}
2回測定しないとレイアウトが小さすぎるかどうかを知る方法はありますか?ドキュメント内にMEASURED_STATE_TOO_SMALL
が見つかりましたが、使用方法はわかりません。 https://developer.android.com/reference/android/view/View.html#getMeasuredHeightAndState()
なぜ「すべて」を保持するために「scrollview」を使用しないのですか?とにかく 'Display'クラスから表示サイズを得ることができます。次に、アイテムの合計サイズを計算します。他のアイテムを削除します。 –
スクロールせずに1画面に情報を表示したい。子供たちが合わないときは、あまり重要でないものは取り除くことができます –