Java Code Examples for android.view.ViewGroup.getChildAt()

The following are Jave code examples for showing how to use getChildAt() of the android.view.ViewGroup class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ImmerseMode   File: TpSbTlNbImmerseMode.java   View Source Code Vote up 7 votes
/**
 * 配置Activity。主要配置Activity的用户视图对状态栏和导航栏的留白
 *
 * @param activity Activity对象,不可为空
 * @throws IllegalStateException
 */
private void setupUserView(@NonNull Activity activity) throws IllegalStateException {
    ViewGroup contentViewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
    final int childViewCount = contentViewGroup.getChildCount();
    if (childViewCount == 0) {
        throw new IllegalStateException("Plz invoke setContentView() method first!");
    } else if (childViewCount > 1) {
        throw new IllegalStateException("Plz set one view in SetContentView() or shouldn't use merge tag!!");
    }

    View userView = contentViewGroup.getChildAt(0);
    userView.setFitsSystemWindows(false);
    ViewGroup.MarginLayoutParams userViewParams = (ViewGroup.MarginLayoutParams) userView.getLayoutParams();
    userViewParams.topMargin += ImmerseGlobalConfig.getInstance().getStatusBarHeight();
    if (mActivityConfig.hasNavigtionBar()) {
        if (mActivityConfig.isNavigationAtBottom()) {
            userViewParams.bottomMargin += mActivityConfig.getNavigationBarHeight();
        } else {
            userViewParams.rightMargin += mActivityConfig.getNavigationBarWidth();
        }
    }
    userView.setLayoutParams(userViewParams);
}
 
Example 2
Project: recyclerview-android   File: ClickableViewFinder.java   View Source Code Vote up 7 votes
@Nullable
private View findViewAt(@NonNull final View view, final float x, final float y) {
    if (!view.isShown() || !view.isEnabled() || !isViewAt(view, x, y)) {
        return null;
    }

    if (view instanceof ViewGroup) {
        final float transformedX = x - view.getLeft() - ViewCompat.getTranslationX(view);
        final float transformedY = y - view.getTop() - ViewCompat.getTranslationY(view);

        final ViewGroup viewGroup = (ViewGroup) view;
        final int childCount = viewGroup.getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = viewGroup.getChildAt(i);
            final View foundView = findViewAt(child, transformedX, transformedY);
            if (foundView != null) {
                return foundView;
            }
        }
    }

    return view;
}
 
Example 3
Project: SliderStatusBar   File: StatusBarUtil.java   View Source Code Vote up 6 votes
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
}
 
Example 4
Project: Rxjava2.0Demo   File: RefreshContentWrapper.java   View Source Code Vote up 6 votes
protected View findScrollableViewByEvent(View content, MotionEvent event, View orgScrollableView) {
    if (content instanceof ViewGroup && event != null) {
        ViewGroup viewGroup = (ViewGroup) content;
        final int childCount = viewGroup.getChildCount();
        PointF point = new PointF();
        for (int i = childCount; i > 0; i--) {
            View child = viewGroup.getChildAt(i - 1);
            if (isTransformedTouchPointInView(viewGroup, child, event.getX(), event.getY(), point)) {
                if (!(child instanceof ViewPager) && isScrollableView(child)) {
                    return child;
                } else {
                    event = MotionEvent.obtain(event);
                    event.offsetLocation(point.x, point.y);
                    return findScrollableViewByEvent(child, event, orgScrollableView);
                }
            }
        }
    }
    return orgScrollableView;
}
 
Example 5
Project: YiZhi   File: CompatNestedScrollView.java   View Source Code Vote up 6 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (getChildCount() > 1) {
        throw new IllegalArgumentException("only can 1 child in this view");
    } else {
        if (getChildAt(0) instanceof ViewGroup) {
            childViewGroup = (ViewGroup) getChildAt(0);
            if (childViewGroup != null) {
                headView = childViewGroup.getChildAt(0);
            }
        } else {
            throw new IllegalArgumentException("child must be instanceof ViewGroup");
        }
    }
}
 
Example 6
Project: boohee_v5.6   File: FragmentTransitionCompat21.java   View Source Code Vote up 6 votes
private static void bfsAddViewChildren(List<View> views, View startView) {
    int startIndex = views.size();
    if (!containedBeforeIndex(views, startView, startIndex)) {
        views.add(startView);
        for (int index = startIndex; index < views.size(); index++) {
            View view = (View) views.get(index);
            if (view instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view;
                int childCount = viewGroup.getChildCount();
                for (int childIndex = 0; childIndex < childCount; childIndex++) {
                    View child = viewGroup.getChildAt(childIndex);
                    if (!containedBeforeIndex(views, child, startIndex)) {
                        views.add(child);
                    }
                }
            }
        }
    }
}
 
Example 7
Project: GravityBox   File: LogUtils.java   View Source Code Vote up 6 votes
private static void showViewGroup(String tag, ViewGroup viewGroup, int deep) {
    StringBuilder tab = new StringBuilder();
    for (int i = 0; i < deep; i++) {
        tab.append("\t\t");
    }
    log(tag, deep + ": " + tab + viewGroup.getClass().getName() + "{");
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View view = viewGroup.getChildAt(i);
        if (view instanceof ViewGroup) {
            showViewGroup(tag, (ViewGroup) view, deep + 1);
        } else {
            log(tag, (deep + 1) + ": " + tab.toString() + "\t\t" + view.getClass().getName());
        }
    }
    log(tag, tab + "\t\t" + "}");
}
 
Example 8
Project: PlusGram   File: RecyclerView.java   View Source Code Vote up 6 votes
private void invalidateDisplayListInt(ViewGroup viewGroup, boolean invalidateThis) {
    for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
        final View view = viewGroup.getChildAt(i);
        if (view instanceof ViewGroup) {
            invalidateDisplayListInt((ViewGroup) view, true);
        }
    }
    if (!invalidateThis) {
        return;
    }
    // we need to force it to become invisible
    if (viewGroup.getVisibility() == View.INVISIBLE) {
        viewGroup.setVisibility(View.VISIBLE);
        viewGroup.setVisibility(View.INVISIBLE);
    } else {
        final int visibility = viewGroup.getVisibility();
        viewGroup.setVisibility(View.INVISIBLE);
        viewGroup.setVisibility(visibility);
    }
}
 
Example 9
Project: recyclerview-android   File: RecursiveEnableBehavior.java   View Source Code Vote up 6 votes
private void setEnabledRecursively(@NonNull final View view, final boolean enabled) {
    view.setEnabled(enabled);

    if (view instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) view;
        final int childCount = viewGroup.getChildCount();
        for (int index = 0; index < childCount; index++) {
            final View child = viewGroup.getChildAt(index);
            setEnabledRecursively(child, enabled);
        }
    }
}
 
Example 10
Project: MyAnimeViewer   File: VideoDetailsFragment.java   View Source Code Vote up 5 votes
private void updateTabLayout() {
    ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
    int tabsCount = vg.getChildCount();
    for (int j = 0; j < tabsCount; j++) {
        ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
        int tabChildsCount = vgTab.getChildCount();
        for (int i = 0; i < tabChildsCount; i++) {
            View tabViewChild = vgTab.getChildAt(i);
            if (tabViewChild instanceof TextView) {
                if (font != null)
                    ((TextView) tabViewChild).setTypeface(font);
            }
        }
    }
}
 
Example 11
Project: TitleBarView   File: KeyboardUtil.java   View Source Code Vote up 5 votes
private KeyboardUtil(Activity activity, Window window) {
    this.mActivity = activity;
    this.mWindow = window;
    this.mDecorView = activity.getWindow().getDecorView();
    ViewGroup frameLayout = (ViewGroup) mWindow.getDecorView().findViewById(android.R.id.content);
    if (frameLayout.getChildAt(0) != null) {
        this.mFlag = true;
    }
    this.mContentView = frameLayout.getChildAt(0) != null ? frameLayout.getChildAt(0) : frameLayout;
}
 
Example 12
Project: duo-navigation-drawer   File: DuoDrawerLayout.java   View Source Code Vote up 5 votes
/**
 * Disables/Enables a view and all of its child views.
 * Leaves the toolbar enabled at all times.
 *
 * @param view    The view to be disabled/enabled
 * @param enabled True or false, enabled/disabled
 */
private void setViewAndChildrenEnabled(View view, boolean enabled) {
    view.setEnabled(enabled);
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof Toolbar) {
                setViewAndChildrenEnabled(child, true);
            } else {
                setViewAndChildrenEnabled(child, enabled);
            }
        }
    }
}
 
Example 13
Project: CustomAndroidOneSheeld   File: PinsColumnContainer.java   View Source Code Vote up 5 votes
private void loadRects(ViewGroup vg) {
    concatenatedLeft = getChildAt(1).getLeft();
    concatenatedTop = getChildAt(1).getTop();
    concatenatedRight = getChildAt(1).getRight();
    cursorParams = (LayoutParams) cursor.getLayoutParams();
    for (int i = 0; i < vg.getChildCount(); i++) {
        if (vg.getChildAt(i) instanceof PinView) {
            PinView v = (PinView) vg.getChildAt(i);
            int type = getType(v);
            if (type != TYPE.DUMMY) {
                v.setBackgroundResource(type);
                childrenRects.add(new PinData(((String) v.getTag()),
                        new Rect(
                                concatenatedLeft
                                        + vg.getLeft()
                                        - (extraHorizontalSpace * (!v
                                        .getTag().toString()
                                        .startsWith("_") ? 2 : 1))
                                        + v.getLeft(), concatenatedTop
                                + vg.getTop() + v.getTop()
                                - extraVerticalSpace,
                                concatenatedTop
                                        + vg.getLeft()
                                        + v.getRight()
                                        + (extraHorizontalSpace * (v
                                        .getTag().toString()
                                        .startsWith("_") ? 2 : 2)),
                                concatenatedTop + vg.getTop()
                                        + v.getBottom()
                                        + extraVerticalSpace), i, type));
            }
        } else if (vg.getChildAt(i) instanceof ViewGroup) {
            loadRects((ViewGroup) vg.getChildAt(i));
        }
    }
}
 
Example 14
Project: ClouldReader   File: StatusBarUtil.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearPreviousSetting(Activity activity) {
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int count = decorView.getChildCount();
    if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
        decorView.removeViewAt(count - 1);
        ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
        rootView.setPadding(0, 0, 0, 0);
    }
}
 
Example 15
Project: Phoenix-for-VK   File: AttachmentsViewBinder.java   View Source Code Vote up 5 votes
private void displayStickers(List<Sticker> stickers, ViewGroup stickersContainer) {
    stickersContainer.setVisibility(safeIsEmpty(stickers) ? View.GONE : View.VISIBLE);
    if (safeIsEmpty(stickers)) {
        return;
    }

    if (stickersContainer.getChildCount() == 0) {
        ImageView localView = new ImageView(mContext);
        stickersContainer.addView(localView);
    }

    ImageView imageView = (ImageView) stickersContainer.getChildAt(0);
    Sticker sticker = stickers.get(0);

    boolean horisontal = sticker.getHeight() < sticker.getWidth();
    double proporsion = (double) sticker.getWidth() / (double) sticker.getHeight();

    float finalWidth;
    float finalHeihgt;

    if (horisontal) {
        finalWidth = dpToPx(PREFFERED_STICKER_SIZE, mContext);
        finalHeihgt = (float) (finalWidth / proporsion);
    } else {
        finalHeihgt = dpToPx(PREFFERED_STICKER_SIZE, mContext);
        finalWidth = (float) (finalHeihgt * proporsion);
    }

    imageView.getLayoutParams().height = (int) finalHeihgt;
    imageView.getLayoutParams().width = (int) finalWidth;

    PicassoInstance.with()
            .load(sticker.getPhoto256())
            .into(imageView);

}
 
Example 16
Project: RNLearn_Project1   File: ReactTestHelper.java   View Source Code Vote up 5 votes
/**
 * Gets the view at given path in the UI hierarchy, ignoring modals.
 */
public static <T extends View> T getViewAtPath(ViewGroup rootView, int... path) {
  // The application root element is wrapped in a helper view in order
  // to be able to display modals. See renderApplication.js.
  ViewGroup appWrapperView = rootView;
  View view = appWrapperView.getChildAt(0);
  for (int i = 0; i < path.length; i++) {
    view = ((ViewGroup) view).getChildAt(path[i]);
  }
  return (T) view;
}
 
Example 17
Project: RewardLayout   File: RewardLayout.java   View Source Code Vote up 5 votes
/**
 * 获取指定framelayout下的礼物view
 * @param index
 * @return
 */
private View getChildGift(int index) {
    View view = null;
    ViewGroup vg = (ViewGroup) getChildAt(index);
    for (int i = 0; i < vg.getChildCount(); i++) {
        if (vg.getChildAt(i).isEnabled()) {
            view = vg.getChildAt(i);
        }
    }
    return view;
}
 
Example 18
Project: LJFramework   File: StatusBarUtil.java   View Source Code Vote up 5 votes
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity 需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow()
                .addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow()
                .clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow()
                .addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) &&
            contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
                     .setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
}
 
Example 19
Project: AndFast   File: Eyes.java   View Source Code Vote up 5 votes
public static void setStatusBarLightMode(Activity activity, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        //判断是否为小米或魅族手机,如果是则将状态栏文字改为黑色
        if (MIUISetStatusBarLightMode(activity, true) || FlymeSetStatusBarLightMode(activity, true)) {
            //设置状态栏为指定颜色
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0
                activity.getWindow().setStatusBarColor(color);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4
                //调用修改状态栏颜色的方法
                setStatusBarColor(activity, color);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //如果是6.0以上将状态栏文字改为黑色,并设置状态栏颜色
            activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            activity.getWindow().setStatusBarColor(color);

            //fitsSystemWindow 为 false, 不预留系统栏位置.
            ViewGroup mContentView = (ViewGroup) activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            View mChildView = mContentView.getChildAt(0);
            if (mChildView != null) {
                ViewCompat.setFitsSystemWindows(mChildView, true);
                ViewCompat.requestApplyInsets(mChildView);
            }
        }
    }
}
 
Example 20
Project: LaunchEnr   File: FocusHelper.java   View Source Code Vote up 4 votes
/**
 * Private helper method to get the CellLayoutChildren given a CellLayout index.
 */
@Thunk private static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex(
        ViewGroup container, int i) {
    CellLayout parent = (CellLayout) container.getChildAt(i);
    return parent.getShortcutsAndWidgets();
}