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.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java

@Override
public void setCurrentItem(int item, boolean anim) {
    if (item < 0) {
        item = 0;// w  w w. java 2  s .  c om
    } else if (item > mAdapter.getCount() - 1) {
        item = mAdapter.getCount() - 1;
    }
    if (mSelectedTabIndex != item) {
        int mPreSelectedTabIndex = mSelectedTabIndex;
        mSelectedTabIndex = item;
        final int tabCount = mAdapter.getCount();
        /*
         * ?tab
         */
        for (int i = 0; i < tabCount; i++) {
            final ViewGroup group = (ViewGroup) getChildAt(i);
            View child = group.getChildAt(0);
            final boolean isSelected = (i == item);
            child.setSelected(isSelected);
        }

        // ???,??
        if (!inRun.isFinished()) {
            inRun.stop();
        }
        // scrollBar?viewpager??
        if (scrollBar != null && mPositionOffset < 0.01f && mPreSelectedTabIndex >= 0
                && mPreSelectedTabIndex < getChildCount()) {
            // ?scrollBar?
            int sx = getChildAt(mPreSelectedTabIndex).getLeft();
            // ?scrollBar??
            int ex = getChildAt(item).getLeft();
            final float pageDelta = (float) Math.abs(ex - sx) / (getChildAt(item).getWidth());
            int duration = (int) ((pageDelta + 1) * 100);
            duration = Math.min(duration, 600);
            // scrollBar
            inRun.startScroll(sx, ex, duration);
        }
        // measureScrollBar(true);
    }
}

From source file:com.app.jdy.activity.GoldActivity.java

/**
 * ?//from  w  w w .j  av a2  s  .co m
 * 
 * @param viewGroup
 * @param flag
 * @return
 */
public View findViewByType(ViewGroup viewGroup, int flag) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View view = viewGroup.getChildAt(i);
        if (view instanceof TextView && flag == 1) {
            return view;
        } else if (view instanceof ImageView && flag == 2) {
            return view;
        } else if (view instanceof ViewGroup) {
            view = findViewByType((ViewGroup) view, flag);
            if (view != null) {
                return view;
            }
        }
    }
    return null;
}

From source file:com.glanznig.beepme.view.ExportActivity.java

private void enableDisableView(View view, boolean enabled) {
    view.setEnabled(enabled);/*from w  w  w .j  av a2  s . c  om*/

    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;

        for (int i = 0; i < group.getChildCount(); i++) {
            enableDisableView(group.getChildAt(i), enabled);
        }
    }
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;/*from   w w w. j ava  2  s .c o  m*/
    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);
}

From source file:com.m1racle.yuedong.ui.widget.PagerSlidingTabStrip.java

/**
 * ViewPager/*from   w w  w  .  j a  v  a 2s  . c  o m*/
 * 
 * @param viewPager
 *            ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.addOnPageChangeListener(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: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.  ja  v  a  2  s  .  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.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ViewPager/*w ww. ja v a  2  s.  c om*/
 * 
 * @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:com.mfh.comna.api.widgets.PagerSlidingTabStrip.java

/**
 * ViewPager/*from w  w  w . j a v a 2s. co  m*/
 * 
 * @param viewPager
 *            ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(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.lgh.tool.myview.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;//  ww w  .  j  av  a 2s  . c  om
    /* ? */
    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.e.library.widget.ESwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup//from   w ww  . j a  v  a  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 RecyclerView || child instanceof AbsListView || child instanceof ScrollView
                    || child instanceof ViewPager || child instanceof WebView) {
                scrollChild = child;
                return;
            }
        }
    }
}