I have a dialog box that contains a RecyclerView . When adding elements, the window becomes taller. How to make the window grow to a certain point? I know that there is a minHeight parameter, but in my case I need the opposite, the maximum height.
|
1 answer
Try this:
Create a class
private static class OnViewGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener { private final static int maxHeight = 130; private View view; public OnViewGlobalLayoutListener(View view) { this.view = view; } @Override public void onGlobalLayout() { if (view.getHeight() > maxHeight) view.getLayoutParams().height = maxHeight; } } Then add a listener to your view (in your case recyclerview):
view.getViewTreeObserver() .addOnGlobalLayoutListener(new OnViewGlobalLayoutListener(view)); - Thank you very much, you helped me a lot) - Ilya Kupriyanov
|