开发者

Threshold for showing View in Android

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 开发者_如何学JAVAif 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜