Example usage for android.view ViewGroup getChildAt

List of usage examples for android.view ViewGroup getChildAt

Introduction

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

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:com.xnf.henghenghui.ui.view.PagerSlidingTabStrip.java

/**
 * ViewPager/*www  .  jav 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);
            }
            if (listener != null)
                listener.onChanged(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:cn.smile.widget.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup//from ww  w .ja va 2  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.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ?/* w w  w  . 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);
            }
        }
    }
}

From source file:com.cicada.startup.common.ui.view.indicator.ViewPagerIndicator.java

/**
 * ViewPager/*  w w w .j a va2 s .c o 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);
            }
            if (listener != null)
                listener.onChanged(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:android.support.v7.internal.view.menu.ActionMenuPresenter.java

@Override
public boolean filterLeftoverView(ViewGroup parent, int childIndex) {
    if (parent.getChildAt(childIndex) == mOverflowButton) {
        return false;
    }/*from  w w  w .  ja v a2  s . com*/
    return super.filterLeftoverView(parent, childIndex);
}

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

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;/*  w  w  w.  j a  v  a  2 s .  co  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);
                }
            }
            slidingBlockDrawable.setBounds((int) slidingBlockLeft, 0, (int) slidingBlockRight, getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

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

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup/*from  w ww.j  a  v a2  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

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);
        }/*from w  w w .j a v a2  s  .com*/
    }
}

From source file:com.mfh.litecashier.ui.widget.TopSlidingTabStrip.java

/**
 * ViewPager//from   w w  w . j  a  va2s  . c om
 * 
 * @param viewPager
 *            ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
            if (listener != null)
                listener.onChanged(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.bowyoung.enhancelibrary.libs.swipeback.SwipeBackLayout.java

public void attachToActivity(BaseEnhanceActivity activity) {
    mActivity = activity;//from   w ww  .j  av a  2  s.c  om
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}