Example usage for android.view ViewGroup getChildCount

List of usage examples for android.view ViewGroup getChildCount

Introduction

In this page you can find the example usage for android.view ViewGroup getChildCount.

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:cn.smile.widget.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup/*w ww  . java2 s .  co m*/
 */
private void findScrollView(ViewGroup viewGroup) {
    scrollChild = viewGroup;
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        View child;
        for (int i = 0; i < count; i++) {
            child = viewGroup.getChildAt(i);
            if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager
                    || child instanceof WebView) {
                scrollChild = child;
                return;
            }
        }
    }
}

From source file:com.cjj.viewpagerlibrary.PagerSlidingTabStrip.java

/**
 * ?//from  ww  w  . ja va2 s. c  om
 */
private void scrollToChild(int position, int offset) {
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && position < tabsLayout.getChildCount()) {
        View view = tabsLayout.getChildAt(position);
        if (view != null) {
            //X??
            int newScrollX = view.getLeft() + offset;
            if (position > 0 || offset > 0) {
                newScrollX -= 240 - getOffset(view.getWidth()) / 2;
            }

            //?X???
            if (newScrollX != lastScrollX) {
                lastScrollX = newScrollX;
                scrollTo(newScrollX, 0);
            }
        }
    }
}

From source file:com.dong.starsmind.widgets.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup// ww w .j a va  2 s.c om
 */
private void findScrollView(ViewGroup viewGroup) {
    scrollChild = viewGroup;
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        View child;
        for (int i = 0; i < count; i++) {
            child = viewGroup.getChildAt(i);
            if (child instanceof AbsListView || child instanceof RecyclerView || child instanceof ScrollView
                    || child instanceof ViewPager || child instanceof WebView) {
                scrollChild = child;
                return;
            }
        }
    }
}

From source file:com.efan.notlonely_android.view.PagerSlidingTabStrip.java

public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;/*from  ww  w  . j a v a2 s  .c  om*/
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {
            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset
                            * (view.getWidth() + getLeftMargin(view) + getRightMargin(view))));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    viewPager.setCurrentItem(1);
    requestLayout();
}

From source file:cn.liuguangqiang.swipeback.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup//  w  ww  . j  a  va  2s  .  c  o  m
 */
private void findScrollView(ViewGroup viewGroup) {
    scrollChild = viewGroup;
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        View child;
        for (int i = 0; i < count; i++) {
            child = viewGroup.getChildAt(i);
            if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager) {
                scrollChild = child;
                return;
            }
        }
    }
}

From source file:com.csipsimple.service.SipNotifications.java

private boolean recurseSearchNotificationPrimaryText(ViewGroup gp) {
    final int count = gp.getChildCount();
    for (int i = 0; i < count; ++i) {
        if (gp.getChildAt(i) instanceof TextView) {
            final TextView text = (TextView) gp.getChildAt(i);
            final String szText = text.getText().toString();
            if (TO_SEARCH.equals(szText)) {
                notificationPrimaryTextColor = text.getTextColors().getDefaultColor();
                return true;
            }//ww  w  .  j ava2 s  . c  o m
        } else if (gp.getChildAt(i) instanceof ViewGroup) {
            if (recurseSearchNotificationPrimaryText((ViewGroup) gp.getChildAt(i))) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.smap.smapTask.android.activities.MainTabsActivity.java

private TextView getTextViewChild(ViewGroup viewGroup) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View view = viewGroup.getChildAt(i);
        if (view instanceof TextView) {
            return (TextView) view;
        }/* w  w w.  jav  a  2 s. c om*/
    }
    return null;
}

From source file:com.cjj.viewpagerlibrary.PagerSlidingTabStrip.java

/**
 * ViewPager/* w  w  w.  j av a 2  s  .  co  m*/
 * @param viewPager ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {
            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset * view.getWidth()));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    requestLayout();
}

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuPresenter.java

private View findViewForItem(MenuItem item) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null)
        return null;

    final int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        if (child instanceof MenuView.ItemView && ((MenuView.ItemView) child).getItemData() == item) {
            return child;
        }/*from   w ww.j  av a  2s. co  m*/
    }
    return null;
}

From source file:arefin.dialogs.core.BaseDialogFragment.java

private boolean isScrollable(ViewGroup listView) {
    int totalHeight = 0;
    for (int i = 0; i < listView.getChildCount(); i++) {
        totalHeight += listView.getChildAt(i).getMeasuredHeight();
    }//from w  ww .  j  a va 2s.  c  o  m
    return listView.getMeasuredHeight() < totalHeight;
}