tags:

views:

26

answers:

2

I have a UI layout that's comprised of a single outer layout that contains three internal layouts. The internal layouts are essentially a header, body and footer.

I would like to cause the top, header view to become completely hidden if it's forced to shrink past a certain threshold. It contains a logo image, and if it shrinks past a certain point, I'd rather just hide it completely.

What's the best way to do this? Is there a way to accomplish this statically in a layout xml? If not, do I need to subclass the View and listen for resizes? Is there another way?

A: 

I don't think you can do it in the XML, but whenever anything happens that could shrink it (you might need to use an onTouchListener() if it's shrunk by the user's finger), you can call getHeight(), and if it's less than a certain value call setVisibility(View.GONE) on it.

infinitypanda
Given, but that's what I'm looking for--good/proper ways to actually listen for that resize.
DougW
How are you resizing it? By touch, by button push, by a list below it becoming large enough, etc.
infinitypanda
By the user turning the phone sideways. I'm not doing it programatically.
DougW
+1  A: 

Subclass your View an override the onLayout or onMeasure methods. That is when the View itself decides its width and height. After onMeasure is completed, you can call this.getMeasuredHeight() and check if its below your threshold. If it is, just hide it.

Moncader