简体   繁体   中英

Android viewGroup listen to child view visibility changes

I have an android custom ViewGroup

I need to receive children visibility changes and then make some change to my logic and ...

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 ...

In your custom ViewGroup , you might have overriden onLayout() and 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 . There is an example in that page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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