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:com.yeahka.mach.android.widget.viewPager.PagerSlidingTabStrip.java

private void resetLayout(ViewGroup viewGroup) {
    if (viewGroup.getChildCount() > 0) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            viewGroup.getChildAt(i).setBackgroundColor(getResources().getColor(android.R.color.white));
        }/*  w  w  w. j ava 2  s  . c o m*/
    }
}

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

private void selectedTab(int newSelectedTabPosition) {
    ViewGroup tabsLayout = getTabsLayout();
    if (newSelectedTabPosition > -1 && tabsLayout != null
            && newSelectedTabPosition < tabsLayout.getChildCount()) {
        for (int w = 0, size = tabsLayout.getChildCount(); w < size; w++) {
            View tabView = tabsLayout.getChildAt(w);
            tabView.setSelected(w == newSelectedTabPosition);
        }/*  w  w  w . j a  va 2  s.co m*/
    }
}

From source file:com.android.launcher2.HideFromAccessibilityHelper.java

private void restoreImportantForAccessibilityHelper(View v) {
    ViewCompat.setImportantForAccessibility(v, mPreviousValues.get(v));
    mPreviousValues.remove(v);/*from  www. ja  va2s. com*/

    // Call method on children recursively
    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;

        // We assume if a class implements OnHierarchyChangeListener, it listens
        // to changes to any of its children (happens to be the case in Launcher)
        if (vg instanceof OnHierarchyChangeListener) {
            vg.setOnHierarchyChangeListener((OnHierarchyChangeListener) vg);
        } else {
            vg.setOnHierarchyChangeListener(null);
        }
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            if (includeView(child)) {
                restoreImportantForAccessibilityHelper(child);
            }
        }
    }
}

From source file:com.artemchep.horario.ui.widgets.SwipeBackLayout.java

private View findScrollViewR(ViewGroup viewGroup) {
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        for (int i = 0; i < count; i++) {
            View view = viewGroup.getChildAt(i);
            if (view instanceof AbsListView || view instanceof ScrollView || view instanceof ScrollingView
                    || view instanceof ViewPager || view instanceof WebView) {
                return view;
            } else if (view instanceof ViewGroup) {
                view = findScrollViewR((ViewGroup) view);
                if (view != null) {
                    return view;
                }/*from w w w  . j  av  a 2  s.c  om*/
            }
        }
    }
    return null;
}

From source file:com.lgh.tool.myview.PagerSlidingTabStrip.java

/**
 * ?//from ww w .  j  a va  2  s  .c o m
 */
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 - getLeftMargin(view);
            if (position > 0 || offset > 0) {
                newScrollX -= getWidth() / 2 - getOffset(view.getWidth()) / 2;
            }

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

From source file:com.kayac.slidingmenu.ui.views.DraggableLayout.java

/**
 * Detect at a specific position of view, its child can scrollHoziontally or not
 * Also support Viewpager as its child//from w  ww  .j  a v a 2s  .c  o  m
 * @param v         view to check
 * @param checkV   check it or not
 * @param dx      Direction
 * @param x         pos X
 * @param y         pos Y
 * @return
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        for (int i = count - 1; i >= 0; i--) {
            final View child = group.getChildAt(i);
            if (child.getVisibility() == View.VISIBLE && x + scrollX >= child.getLeft()
                    && x + scrollX < child.getRight() && y + scrollY >= child.getTop()
                    && y + scrollY < child.getBottom() && canScroll(child, true, dx,
                            x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return (checkV && (ViewCompat.canScrollHorizontally(v, -dx) || (v instanceof ViewPager)));
}

From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    ViewGroup tabViewGroup = getTabsLayout();

    // //from   w  w  w  .j  a  va2  s. co m
    if (tabViewGroup == null || tabViewGroup.getChildCount() <= 0) {
        super.onLayout(changed, l, t, r, b);
        return;
    }

    int viewWidth = r - l;

    // Item
    if ((measure(tabViewGroup).getMeasuredWidth() < viewWidth) && allowWidthFull) {
        // ?tabViewGroup??
        viewWidth -= tabViewGroup.getPaddingLeft();
        viewWidth -= tabViewGroup.getPaddingRight();
        if (tabViewGroup.getLayoutParams() instanceof MarginLayoutParams) {
            MarginLayoutParams tabsLayoutParams = (MarginLayoutParams) tabViewGroup.getLayoutParams();
            viewWidth -= tabsLayoutParams.leftMargin;
            viewWidth -= tabsLayoutParams.rightMargin;
        }

        // ??Tab?
        View tabView;
        for (int w = 0; w < tabViewGroup.getChildCount(); w++) {
            tabView = tabViewGroup.getChildAt(w);
            if (tabView.getLayoutParams() instanceof MarginLayoutParams) {
                MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams();
                viewWidth -= marginLayoutParams.leftMargin;
                viewWidth -= marginLayoutParams.rightMargin;
            }
        }

        // ?
        int averageWidth = viewWidth / tabViewGroup.getChildCount();
        int bigTabCount = 0; // ?tab???
        for (int w = 0; w < tabViewGroup.getChildCount(); w++) {
            tabView = tabViewGroup.getChildAt(w);
            // ????
            if (tabView != null && tabView.getMeasuredWidth() > averageWidth) {
                viewWidth -= tabView.getMeasuredWidth();
                bigTabCount++;
            }
        }

        // ?
        averageWidth = viewWidth / (tabViewGroup.getChildCount() - bigTabCount);

        // ??Item
        for (int w = 0; w < tabViewGroup.getChildCount(); w++) {
            //?????
            tabView = tabViewGroup.getChildAt(w);
            if (tabView != null) {
                ViewGroup.LayoutParams layoutParams = tabView.getLayoutParams();
                if (layoutParams != null) {
                    layoutParams.width = tabView.getMeasuredWidth() < averageWidth ? averageWidth
                            : tabView.getMeasuredWidth();
                    tabView.setLayoutParams(layoutParams);
                    measure(tabView);
                }
            }
        }
        measure(tabViewGroup);
    }

    // ?????
    currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0;
    scrollToChild(currentPosition, 0); //??
    selectedTab(currentPosition); //?TAB

    //?tab?Pager
    for (int w = 0; w < tabViewGroup.getChildCount(); w++) {
        View itemView = tabViewGroup.getChildAt(w);
        itemView.setTag(w);
        itemView.setOnClickListener(this);
    }

    super.onLayout(changed, l, t, r, b);
}

From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ?Tab/* w  ww  .  j  av  a 2  s.  co m*/
 */
public int getTabCount() {
    ViewGroup tabsLayout = getTabsLayout();
    return tabsLayout != null ? tabsLayout.getChildCount() : 0;
}

From source file:com.lgh.tool.myview.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;/*www .  j a  v a2 s. c o m*/
    /* ? */
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && slidingBlockDrawable != null) {
        View currentTab = tabsLayout.getChildAt(currentPosition);
        if (currentTab != null) {
            float slidingBlockLeft = currentTab.getLeft();
            float slidingBlockRight = currentTab.getRight();
            if (currentPositionOffset > 0f && currentPosition < tabsLayout.getChildCount() - 1) {
                View nextTab = tabsLayout.getChildAt(currentPosition + 1);
                if (nextTab != null) {
                    final float nextTabLeft = nextTab.getLeft();
                    final float nextTabRight = nextTab.getRight();
                    slidingBlockLeft = (currentPositionOffset * nextTabLeft
                            + (1f - currentPositionOffset) * slidingBlockLeft);
                    slidingBlockRight = (currentPositionOffset * nextTabRight
                            + (1f - currentPositionOffset) * slidingBlockRight);
                }
            }

            // ?
            if (disableTensileSlidingBlock) {
                int center = (int) (slidingBlockLeft + (slidingBlockRight - slidingBlockLeft) / 2);
                slidingBlockLeft = center - slidingBlockDrawable.getIntrinsicWidth() / 2;
                slidingBlockRight = center + slidingBlockDrawable.getIntrinsicWidth() / 2;
            }

            slidingBlockDrawable.setBounds((int) slidingBlockLeft,
                    getHeight() - slidingBlockDrawable.getIntrinsicHeight(), (int) slidingBlockRight,
                    getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ?//from  w ww.j av a 2 s .c  o  m
 */
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);
            }
        }
    }
}