List of usage examples for android.view ViewGroup getChildCount
public int getChildCount()
From source file:com.along.practice.widget.swipbacklayout.ViewDragHelper.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dx Delta scrolled in pixels along the X axis * @param dy Delta scrolled in pixels along the Y axis * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. *//*from ww w. ja v a2 s . co m*/ protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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(); // Count backwards - let topmost views consume scroll distance // first. for (int i = count - 1; i >= 0; i--) { // Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }
From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dx Delta scrolled in pixels * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. *//*from w w w . ja va 2s .c om*/ protected boolean canScroll(final View v, final boolean checkV, final int dx, final int x, final 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(); // Count backwards - let topmost views consume scroll distance // first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (((x + scrollX) >= child.getLeft()) && ((x + scrollX) < child.getRight()) && ((y + scrollY) >= child.getTop()) && ((y + scrollY) < child.getBottom()) && this.canScroll(child, true, dx, (x + scrollX) - child.getLeft(), (y + scrollY) - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollHorizontally(v, -dx); }
From source file:com.youle.gamebox.ui.view.SlidingPaneLayout.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). * @param dx Delta scrolled in pixels//from w w w .j a v a 2 s . co m * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ 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(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); // if(!child.isAttachedToWindow()) continue; if (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) && canViewPagerScrollHorizontally((ViewPager) v, -dx))); }
From source file:org.de.jmg.learn.SettingsActivity.java
private void resize(float scale) { //if (scale == 0 && mScale!=1) return; Resources resources = _main.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); @SuppressWarnings("unused") int Density = metrics.densityDpi; try {/*from ww w . ja v a 2 s.c om*/ int width = mainView.getWidth(); if (width > 500) { width -= lib.dpToPx(40); } else { width -= lib.dpToPx(40); } if (scale == 0) { mainView.setVisibility(View.INVISIBLE); libLearn.gStatus = "Calculating Scale"; float scale1 = width / (float) (_main.isSmallDevice ? 0 : (findViewById(R.id.txtCharsetASCII)).getWidth() + spnASCII.getWidth() + width / 30); float scale2 = width / (float) (_main.isSmallDevice ? 0 : (findViewById(R.id.txtSounds)).getWidth() + spnSounds.getWidth() + width / 30); float scale3 = width / (float) (_main.isSmallDevice ? 0 : (findViewById(R.id.txtCharsetASCII)).getWidth() + spnASCII.getWidth() + width / 30); scale = (scale1 < scale2) ? scale1 : scale2; scale = (scale3 < scale) ? scale3 : scale; } mScale = scale; ViewGroup Settings = (ViewGroup) findViewById(R.id.layoutSettings); libLearn.gStatus = "Enumerating ChildViews"; int ChildCount = Settings.getChildCount(); for (int i = 0; i < ChildCount; i++) { if (i > 100) break; libLearn.gStatus = "getting view " + i; View V = Settings.getChildAt(i); /* CharSequence cs = V.getContentDescription(); if (cs != null && cs.length()>0 ) { V.setOnLongClickListener(ViewOnLongClickCD); } */ RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) V .getLayoutParams(); params.topMargin = (int) (params.topMargin * scale); params.bottomMargin = (int) (params.bottomMargin * scale); if (params.height > 0) params.height = (int) (params.height * scale); if (V instanceof CheckBox) { if (params.width > 0) params.width = ((width - lib.dpToPx(10)) / 3); } else { if (params.width > 0) params.width = (int) (params.width * scale); } /* if (V == spnSounds) { int soundsHeight = spnSounds.getHeight(); float margin = (float) ((soundsHeight * scale) / 5.25); params.topMargin = params.topMargin + (int) margin; } */ libLearn.gStatus = "Setting Layoutparams"; V.setLayoutParams(params); // } if (V instanceof TextView && !(V instanceof CheckBox)) { libLearn.gStatus = "TextView set size"; TextView t = (TextView) V; t.setTextSize(TypedValue.COMPLEX_UNIT_PX, t.getTextSize() * scale); } else if (V instanceof Spinner) { Spinner spn = (Spinner) V; SpinnerAdapter A = spn.getAdapter(); if (A instanceof AbstractScaledArrayAdapter<?>) { libLearn.gStatus = "Scaling Adapter"; AbstractScaledArrayAdapter<?> AA = (AbstractScaledArrayAdapter<?>) A; AA.Scale = AA.Scale * scale; if (spn.getSelectedItemPosition() > -1) { AA.notifyDataSetChanged(); } } } else if (V instanceof CheckBox) { libLearn.gStatus = "CheckBox"; CheckBox c = (CheckBox) V; //c.setScaleX(scale); //c.setScaleY(scale); // c.setle c.setTextSize(TypedValue.COMPLEX_UNIT_PX, c.getTextSize() * scale); /* int p1 = c.getPaddingTop(); int p2 = c.getPaddingBottom(); int p3 = c.getPaddingLeft(); int p4 = c.getPaddingRight(); c.setPadding((int) (p3/scale), p1, p4, p2); */ //LevelListDrawable D = (LevelListDrawable) c.getBackground(); /* Drawable d = c.getBackground(); Log.d("bounds", d.getBounds().toString()); */ //d.setTargetDensity((int) (Density * scale)); //d.setBounds(0, 0, c.getHeight(), c.getHeight()); //lib.setBgCheckBox(c,d); /* ViewGroup check = (ViewGroup) V; for (int ii = 0; ii<check.getChildCount(); ii++) { View cv = check.getChildAt(ii); String cls = cv.getClass().getName(); Log.d("Classs", cls); } */ // Drawable d = lib.getDefaultCheckBoxDrawable(_main); // d = new ScaleDrawable(d, 0, c.getHeight()*scale, // c.getHeight()*scale).getDrawable(); // float scaleC = (float)c.getHeight()/d.getBounds().height(); // d.setBounds(0, 0,(int) (c.getHeight()*scale),(int) // (c.getHeight()*scale)); // LayerDrawable L = new LayerDrawable(new Drawable[]{d}); // d = lib.scaleImage(_main, d, scaleC); // /c.setButtonDrawable(d); } } /* libLearn.gStatus="Buttons"; Button b = (Button) findViewById(R.id.btnOK); RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) b .getLayoutParams(); params.topMargin = (int) (params.topMargin * scale); if (params.height>0)params.height = (int) (params.height * scale); if (params.width>0)params.width = (int) (params.width * scale); b.setLayoutParams(params); b.setTextSize(TypedValue.COMPLEX_UNIT_PX, b.getTextSize() * scale); b = (Button) findViewById(R.id.btnCancel); params = (android.widget.RelativeLayout.LayoutParams) b .getLayoutParams(); params.topMargin = (int) (params.topMargin * scale); if (params.height>0)params.height = (int) (params.height * scale); if (params.width>0)params.width = (int) (params.width * scale); b.setLayoutParams(params); b.setTextSize(TypedValue.COMPLEX_UNIT_PX, b.getTextSize() * scale); */ SettingsView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Ensure you call it only once : lib.removeLayoutListener(SettingsView.getViewTreeObserver(), this); int pos = spnASCII.getSelectedItemPosition(); spnASCII.setSelection(-1); spnASCII.setSelection(pos); } }); } catch (Exception ex) { lib.ShowException(_main, ex); } finally { mainView.setVisibility(View.VISIBLE); } }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
private boolean isDrawerViewOrChild(View child) { if (child == mDrawerView) return true; if (mDrawerView instanceof ViewGroup) { ViewGroup parent = (ViewGroup) mDrawerView; int count = parent.getChildCount(); for (int i = 0; i < count; i++) { if (parent.getChildAt(i) == child) return true; }/*w ww .j a v a 2 s. c o m*/ } return false; }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
View findTopChildUnder(View view, int x, int y) { if (view instanceof ViewGroup) { ViewGroup parent = (ViewGroup) view; final int childCount = parent.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { final View child = parent.getChildAt(i); if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { return child; }// ww w . j a v a2 s.c o m } } return null; }
From source file:com.baidayi.swipback.ViewDragHelper.java
/** * Tests scrollability within child views of v given a delta of dx. * /*w w w . ja v a 2s . c o m*/ * @param v * View to test for horizontal scrollability * @param checkV * Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dx * Delta scrolled in pixels along the X axis * @param dy * Delta scrolled in pixels along the Y axis * @param x * X coordinate of the active touch point * @param y * Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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(); // Count backwards - let topmost views consume scroll distance // first. for (int i = count - 1; i >= 0; i--) { // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }
From source file:android.improving.utils.views.swipeback.ViewDragHelper.java
/** * Tests scrollability within child views of v given a delta of dx. * /*from ww w.j a v a 2 s . c o m*/ * @param v * View to test for horizontal scrollability * @param checkV * Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dx * Delta scrolled in pixels along the X axis * @param dy * Delta scrolled in pixels along the Y axis * @param x * X coordinate of the active touch point * @param y * Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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(); // Count backwards - let topmost views consume scroll distance // first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }
From source file:android.support.v7.preference.Preference.java
/** * Makes sure the view (and any children) get the enabled state changed. *//*from ww w .j a v a 2 s . com*/ private void setEnabledStateOnViews(View v, boolean enabled) { v.setEnabled(enabled); if (v instanceof ViewGroup) { final ViewGroup vg = (ViewGroup) v; for (int i = vg.getChildCount() - 1; i >= 0; i--) { setEnabledStateOnViews(vg.getChildAt(i), enabled); } } }
From source file:android.support.transition.Transition.java
/** * Recursive method which captures values for an entire view hierarchy, * starting at some root view. Transitions without targetIDs will use this * method to capture values for all possible views. * * @param view The view for which to capture values. Children of this View * will also be captured, recursively down to the leaf nodes. * @param start true if values are being captured in the start scene, false * otherwise.//w ww . j a va2 s.c o m */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } boolean isListViewItem = false; if (view.getParent() instanceof ListView) { isListViewItem = true; } if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) { // ignore listview children unless we can track them with stable IDs return; } int id = View.NO_ID; long itemId = View.NO_ID; if (!isListViewItem) { id = view.getId(); } else { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); itemId = listview.getItemIdAtPosition(position); ViewCompat.setHasTransientState(view, true); } if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) { return; } if (mTargetExcludes != null && mTargetExcludes.contains(view)) { return; } if (mTargetTypeExcludes != null && view != null) { int numTypes = mTargetTypeExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeExcludes.get(i).isInstance(view)) { return; } } } TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } if (start) { if (!isListViewItem) { mStartValues.viewValues.put(view, values); if (id >= 0) { mStartValues.idValues.put((int) id, values); } } else { mStartValues.itemIdValues.put(itemId, values); } } else { if (!isListViewItem) { mEndValues.viewValues.put(view, values); if (id >= 0) { mEndValues.idValues.put((int) id, values); } } else { mEndValues.itemIdValues.put(itemId, values); } } if (view instanceof ViewGroup) { // Don't traverse child hierarchy if there are any child-excludes on this view if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) { return; } if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) { return; } if (mTargetTypeChildExcludes != null && view != null) { int numTypes = mTargetTypeChildExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeChildExcludes.get(i).isInstance(view)) { return; } } } ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); ++i) { captureHierarchy(parent.getChildAt(i), start); } } }