Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxHeight on FlowLayout #10

Open
lawloretienne opened this issue Oct 6, 2014 · 4 comments
Open

MaxHeight on FlowLayout #10

lawloretienne opened this issue Oct 6, 2014 · 4 comments

Comments

@lawloretienne
Copy link

How do you set a maxHeight on the FlowLayout? Ideally I would have the FlowLayout set to android:layout_height="wrap_content" in xml, and then have a way to set the maxHeight of this FlowLayout.

@blazsolar
Copy link
Owner

At the moment you can't do that. FlowLayout extends ViewGroup which only supports minHeight but not maxHeight. But you could easily do this in your code. By checking view height in onPreDrawListener.

@lawloretienne
Copy link
Author

Can you show an example of how you would do it in onPreDrawListener?

@lawloretienne
Copy link
Author

I tried setting the maxHeight like this

https://gist.github.com/lawloretienne/e79b16d285b94b64b473

But then the views inside the FlowLayout never get displayed, unless this FlowLayout is scrolled off screen and then back on screen.

@blazsolar
Copy link
Owner

I was thinking something like this

// onCreate of your activity/fragment
// at this point flowLayout height should be set to wrap_content
flowLayout.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
    public void onPreDraw() {
        flowLayout.getViewTreeObserver().removePreDrawListener(this)

        if(flowLayout.getHeight > maxHeight) {
            flowLayout.getLayoutParams().height = maxHeight;
        }

        return false;
    }
})

This is from top of my head so it may not work right away. But it should with a bit of twerking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants