Java Code Examples for android.view.ViewGroup#removeViewAt()

The following examples show how to use android.view.ViewGroup#removeViewAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtils.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
/**
 * 调整 parent 的 child views 到指定的数量,并存入 target
 */
@SuppressWarnings("unchecked")
public static <V extends View> void fitChildViews(ViewGroup parent, V[] target, ViewPool<V> pool) {
    int childCount = parent.getChildCount();
    // 移除多出的项
    while (target.length < childCount) {
        V view = (V) parent.getChildAt(0);
        parent.removeViewAt(0);
        pool.recycle(view);
        childCount--;
    }
    // 收集已有的项
    for (int i = 0; i < childCount; i++) {
        target[i] = (V) parent.getChildAt(i);
    }
    // 添加并收集新增的项
    while (target.length > childCount) {
        target[childCount] = pool.obtain(parent);
        parent.addView(target[childCount]);
        childCount++;
    }
}
 
Example 2
Source File: TrackerManager.java    From android_viewtracker with Apache License 2.0 6 votes vote down vote up
private void detachTrackerFrameLayout(Activity activity) {
    if (activity == null || activity instanceof TabActivity) {
        return;
    }

    try {
        ViewGroup container = (ViewGroup) activity.findViewById(android.R.id.content);

        if (container == null) {
            return;
        }

        if (container.getChildAt(0) instanceof TrackerFrameLayout) {
            container.removeViewAt(0);
        }
    } catch (Exception e) {
        TrackerLog.e(e.toString());
    }

}
 
Example 3
Source File: ViewUtils.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
/**
 * 调整 parent 的 child views 到指定的数量,并存入 target
 */
@SuppressWarnings("unchecked")
public static <V extends View> void fitChildViews(ViewGroup parent, V[] target, ViewPool<V> pool) {
    int childCount = parent.getChildCount();
    // 移除多出的项
    while (target.length < childCount) {
        V view = (V) parent.getChildAt(0);
        parent.removeViewAt(0);
        pool.recycle(view);
        childCount--;
    }
    // 收集已有的项
    for (int i = 0; i < childCount; i++) {
        target[i] = (V) parent.getChildAt(i);
    }
    // 添加并收集新增的项
    while (target.length > childCount) {
        target[childCount] = pool.obtain(parent);
        parent.addView(target[childCount]);
        childCount++;
    }
}
 
Example 4
Source File: Tips.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
public View applyTo(View target, int tipsId) {
    mTargetView = target;
    ViewGroup parent = (ViewGroup) target.getParent();
    if (parent == null) {
        return null;
    }
    View tipsView;
    if (parent instanceof TipsContainer) {
        tipsView = addTipsViewToContainer(target, parent, tipsId);
    } else {
        TipsContainer tipsContainerView = new TipsContainer(target.getContext());
        ViewGroup.LayoutParams targetParams = target.getLayoutParams();
        int index = parent.indexOfChild(target);
        parent.removeViewAt(index);
        parent.addView(tipsContainerView, index, targetParams);
        Drawable background = target.getBackground();
        if (background != null) {
            tipsContainerView.setBackground(background);
        }
        tipsView = addTipsViewToContainer(target, tipsContainerView, tipsId);
    }
    return tipsView;
}
 
Example 5
Source File: ActionBarPullToRefresh.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
        PullToRefreshLayout pullToRefreshLayout) {
    // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
    // indices change every time we remove a View (so we can't just iterate through)
    View child = viewGroup.getChildAt(0);
    while (child != null) {
        viewGroup.removeViewAt(0);
        pullToRefreshLayout.addView(child);
        child = viewGroup.getChildAt(0);
    }

    viewGroup.addView(pullToRefreshLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
}
 
Example 6
Source File: TipsUtils.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void removeContainerView(ViewGroup tipsContainerView, View targetView) {
    ViewGroup parent = (ViewGroup) tipsContainerView.getParent();
    ViewGroup.LayoutParams targetParams = tipsContainerView.getLayoutParams();
    int index = parent.indexOfChild(tipsContainerView);
    parent.removeViewAt(index);
    if (targetView.getParent() != null) {
        ((ViewGroup) targetView.getParent()).removeView(targetView);
    }
    parent.addView(targetView, index, targetParams);
}
 
Example 7
Source File: LabelView.java    From labelview with Apache License 2.0 5 votes vote down vote up
public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;
    }

    ViewGroup frameContainer = (ViewGroup) getParent();
    assert (frameContainer.getChildCount() == 2);
    View target = frameContainer.getChildAt(0);

    ViewGroup parentContainer = (ViewGroup) frameContainer.getParent();
    int groupIndex = parentContainer.indexOfChild(frameContainer);
    if (frameContainer.getParent() instanceof RelativeLayout) {
        for (int i = 0; i < parentContainer.getChildCount(); i++) {
            if (i == groupIndex) {
                continue;
            }
            View view = parentContainer.getChildAt(i);
            RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
            for (int j = 0; j < para.getRules().length; j++) {
                if (para.getRules()[j] == _labelViewContainerID) {
                    para.getRules()[j] = target.getId();
                }
            }
            view.setLayoutParams(para);
        }
    }

    ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams();
    target.setLayoutParams(frameLayoutParam);
    parentContainer.removeViewAt(groupIndex);
    frameContainer.removeView(target);
    frameContainer.removeView(this);
    parentContainer.addView(target,groupIndex);
    _labelViewContainerID = -1;
}
 
Example 8
Source File: AdViewWrappingStrategy.java    From admobadapter with Apache License 2.0 5 votes vote down vote up
/**
 * This method can be overriden to recycle (remove) {@param ad} from {@param wrapper} view before adding to wrap.
 * By default it will look for {@param ad} in the direct children of {@param wrapper} and remove the first occurence.
 * See the super's implementation for instance.
 * The NativeExpressHolder recycled by the RecyclerView may be a different
 * instance than the one used previously for this position. Clear the
 * wrapper of any subviews in case it has a different
 * AdView associated with it
 */
@Override
protected void recycleAdViewWrapper(@NonNull ViewGroup wrapper, @NonNull NativeExpressAdView ad) {
    for (int i = 0; i < wrapper.getChildCount(); i++) {
        View v = wrapper.getChildAt(i);
        if (v instanceof NativeExpressAdView) {
            wrapper.removeViewAt(i);
            break;
        }
    }
}
 
Example 9
Source File: AlertPage.java    From Paginize with MIT License 5 votes vote down vote up
public AlertPage setContentView(View view) {
    ViewGroup parent = (ViewGroup)mTvContent.getParent();
    int index = parent.indexOfChild(mTvContent);
    parent.removeViewAt(index);
    parent.addView(view, index);
    return this;
}
 
Example 10
Source File: StatusBarUtil.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ActionBarPullToRefresh.java    From KlyphMessenger with MIT License 5 votes vote down vote up
private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
        PullToRefreshLayout pullToRefreshLayout) {
    // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
    // indices change every time we remove a View (so we can't just iterate through)
    View child = viewGroup.getChildAt(0);
    while (child != null) {
        viewGroup.removeViewAt(0);
        pullToRefreshLayout.addView(child);
        child = viewGroup.getChildAt(0);
    }

    viewGroup.addView(pullToRefreshLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
}
 
Example 12
Source File: PullToRefreshBaseListFragment.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
@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);
	mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState);
	parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams());

	return layout;
}
 
Example 13
Source File: BaseContainerFragment.java    From TemplateAppProject with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    //屏幕旋转时刷新一下title
    super.onConfigurationChanged(newConfig);
    ViewGroup root = (ViewGroup) getRootView();
    if (root.getChildAt(0) instanceof TitleBar) {
        root.removeViewAt(0);
        initTitle();
    }
}
 
Example 14
Source File: StatusBarUtil.java    From TLint with Apache License 2.0 5 votes vote down vote up
/**
 * 添加半透明矩形条
 *
 * @param activity       需要设置的 activity
 * @param statusBarAlpha 透明值
 */
private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    // 移除半透明矩形,以免叠加
    if (contentView.getChildCount() > 1) {
        contentView.removeViewAt(1);
    }
    contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
}
 
Example 15
Source File: ActionBarPullToRefresh.java    From Klyph with MIT License 5 votes vote down vote up
private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
        PullToRefreshLayout pullToRefreshLayout) {
    // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
    // indices change every time we remove a View (so we can't just iterate through)
    View child = viewGroup.getChildAt(0);
    while (child != null) {
        viewGroup.removeViewAt(0);
        pullToRefreshLayout.addView(child);
        child = viewGroup.getChildAt(0);
    }

    viewGroup.addView(pullToRefreshLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
}
 
Example 16
Source File: FragmentManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Moves a fragment to its expected final state or the fragment manager's state, depending
 * on whether the fragment manager's state is raised properly.
 *
 * @param f The fragment to change.
 */
void moveFragmentToExpectedState(final Fragment f) {
    if (f == null) {
        return;
    }
    int nextState = mCurState;
    if (f.mRemoving) {
        if (f.isInBackStack()) {
            nextState = Math.min(nextState, Fragment.CREATED);
        } else {
            nextState = Math.min(nextState, Fragment.INITIALIZING);
        }
    }

    moveToState(f, nextState, f.getNextTransition(), f.getNextTransitionStyle(), false);

    if (f.mView != null) {
        // Move the view if it is out of order
        Fragment underFragment = findFragmentUnder(f);
        if (underFragment != null) {
            final View underView = underFragment.mView;
            // make sure this fragment is in the right order.
            final ViewGroup container = f.mContainer;
            int underIndex = container.indexOfChild(underView);
            int viewIndex = container.indexOfChild(f.mView);
            if (viewIndex < underIndex) {
                container.removeViewAt(viewIndex);
                container.addView(f.mView, underIndex);
            }
        }
        if (f.mIsNewlyAdded && f.mContainer != null) {
            // Make it visible and run the animations
            f.mView.setTransitionAlpha(1f);
            f.mIsNewlyAdded = false;
            // run animations:
            Animator anim = loadAnimator(f, f.getNextTransition(), true, f.getNextTransitionStyle());
            if (anim != null) {
                anim.setTarget(f.mView);
                setHWLayerAnimListenerIfAlpha(f.mView, anim);
                anim.start();
            }
        }
    }
    if (f.mHiddenChanged) {
        completeShowHideFragment(f);
    }
}
 
Example 17
Source File: TabularContextMenuPagerAdapter.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    position = adjustIndexForDirectionality(position, getCount());
    container.removeViewAt(position);
}
 
Example 18
Source File: ThemeClass.java    From heads-up with GNU General Public License v3.0 4 votes vote down vote up
/**
* Remove all action buttons from the layout, in case the layout needs to be re-used.
*/
public void removeActionButtons (ViewGroup actionButtonViewGroup) {
    while (actionButtonViewGroup.getChildCount() > 0) {
        actionButtonViewGroup.removeViewAt(0);
    }
}
 
Example 19
Source File: BaseMenuPresenter.java    From zen4android with MIT License 2 votes vote down vote up
/**
 * Filter the child view at index and remove it if appropriate.
 * @param parent Parent to filter from
 * @param childIndex Index to filter
 * @return true if the child view at index was removed
 */
protected boolean filterLeftoverView(ViewGroup parent, int childIndex) {
    parent.removeViewAt(childIndex);
    return true;
}
 
Example 20
Source File: BaseMenuPresenter.java    From zhangshangwuda with Apache License 2.0 2 votes vote down vote up
/**
 * Filter the child view at index and remove it if appropriate.
 * @param parent Parent to filter from
 * @param childIndex Index to filter
 * @return true if the child view at index was removed
 */
protected boolean filterLeftoverView(ViewGroup parent, int childIndex) {
    parent.removeViewAt(childIndex);
    return true;
}