简体   繁体   English

Android viewGroup侦听子视图的可见性更改

[英]Android viewGroup listen to child view visibility changes

I have an android custom ViewGroup 我有一个android自定义ViewGroup

I need to receive children visibility changes and then make some change to my logic and ... 我需要接收孩子的visibility更改,然后对我的逻辑进行一些更改,并...

for example: I set view1 in a RelativeLayout above view2 and when view2 set it's visibility to GONE I must change view1 design roles and ... 例如:我设定view1RelativeLayout上述view2 ,当view2设置它的visibility ,以GONE我必须改变view1设计角色和...

In your custom ViewGroup , you might have overriden onLayout() and onMeasure() . 在自定义ViewGroup ,您可能已覆盖onLayout()onMeasure() Inside these methods you could just get how many child are there and they visibility status. 在这些方法中,您可以得到那里有多少个孩子,并且它们的可见性状态。

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
             final View child = getChildAt(i);
             if (child.getVisibility() != GONE) {
                 // Measure the child or do whatever you want
             }
        }

More info here: http://developer.android.com/reference/android/view/ViewGroup.html . 此处的更多信息: http : //developer.android.com/reference/android/view/ViewGroup.html There is an example in that page. 该页面中有一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM