List of usage examples for android.view ViewGroup indexOfChild
public int indexOfChild(View child)
From source file:Main.java
public static void moveToBack(View currentView) { ViewGroup vg = ((ViewGroup) currentView.getParent()); int index = vg.indexOfChild(currentView); for (int i = 0; i < index; i++) { vg.bringChildToFront(vg.getChildAt(0)); }/* w ww . j a va2s . c om*/ }
From source file:Main.java
public static void swapViewGroupChildren(ViewGroup viewGroup, View firstView, View secondView) { int firstIndex = viewGroup.indexOfChild(firstView); int secondIndex = viewGroup.indexOfChild(secondView); if (firstIndex < secondIndex) { viewGroup.removeViewAt(secondIndex); viewGroup.removeViewAt(firstIndex); viewGroup.addView(secondView, firstIndex); viewGroup.addView(firstView, secondIndex); } else {/*from ww w. ja va 2 s . com*/ viewGroup.removeViewAt(firstIndex); viewGroup.removeViewAt(secondIndex); viewGroup.addView(firstView, secondIndex); viewGroup.addView(secondView, firstIndex); } }
From source file:Main.java
private static void wrapView(View view, ViewGroup wrapper) { final ViewParent parent = view.getParent(); if (parent != null && parent instanceof ViewGroup) { final ViewGroup parentViewGroup = (ViewGroup) parent; // Wrapper should have same layout params as the previous view had ViewGroup.LayoutParams previousLayoutParams = view.getLayoutParams(); final int indexOfChild = parentViewGroup.indexOfChild(view); parentViewGroup.removeView(view); parentViewGroup.addView(wrapper, indexOfChild, previousLayoutParams); }/*from w w w . j a v a 2 s .c o m*/ wrapper.addView(view); }
From source file:org.smssecure.smssecure.util.ViewUtil.java
public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) { int childIndex = parent.indexOfChild(toRemove); if (childIndex > -1) parent.removeView(toRemove);/*from www .j av a 2 s . com*/ parent.addView(toAdd, childIndex > -1 ? childIndex : defaultIndex); }
From source file:com.linkbubble.util.Util.java
static public void replaceViewAtPosition(View viewToReplace, View replaceWith) { ViewGroup parent = (ViewGroup) viewToReplace.getParent(); int index = parent.indexOfChild(viewToReplace); parent.removeView(viewToReplace);//from w ww . j a va 2 s .c o m parent.addView(replaceWith, index); }
From source file:com.dv.View.PullToRefresh.ListFragment.DvBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add DvListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);// ww w . j av a 2 s. c om mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:com.benefit.buy.library.pulltorefresh.library.listfragment.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);/* w w w .j a v a2s.c o m*/ mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:club.xlxk.libs.pulltorefresh.library.extras.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);//w w w.j a va2 s . c om mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:jp.mydns.sys1yagi.android.viewsticker.ViewSticker.java
private ViewGroup wrap(final View target, final ScrollView monitored, final ViewGroup container) { ViewGroup parent = (ViewGroup) target.getParent(); int index = parent.indexOfChild(target); parent.removeView(target);/*from w ww . j av a 2s . co m*/ final int[] dimension = new int[2]; FrameLayout stuffing = new FrameLayout(target.getContext()) { ViewTreeObserver.OnScrollChangedListener mObserver = new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { monitored.getLocationOnScreen(dimension); int offset = dimension[1]; getLocationOnScreen(dimension); int top = dimension[1] - offset; offset(target, top); if (top < 0 && indexOfChild(target) >= 0) { removeView(target); container.addView(target); } else if (top >= 0 && indexOfChild(target) < 0) { container.removeView(target); addView(target); } } }; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); measureChildWithMargins(target, widthMeasureSpec, 0, heightMeasureSpec, 0); setMeasuredDimension(widthSpecSize, heightSpecSize + target.getMeasuredHeight()); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); monitored.getViewTreeObserver().addOnScrollChangedListener(mObserver); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); monitored.getViewTreeObserver().removeOnScrollChangedListener(mObserver); } }; stuffing.addView(target); parent.addView(stuffing, index); return stuffing; }
From source file:com.minglang.pulltorefreshlibrary.listfragment.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = null;//from ww w . j ava 2 s. c o m if (layout != null) { lv = (ListView) layout.findViewById(android.R.id.list); } ViewGroup parent = null; if (lv != null) { parent = (ViewGroup) lv.getParent(); } // Remove ListView and add PullToRefreshListView in its place int lvIndex = 0; if (parent != null) { lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex); mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); } return layout; }