Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

In this page you can find the example usage for android.view ViewGroup removeView.

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:com.github.markzhai.react.preloader.ReactPreLoader.java

/**
 * Remove {@link ReactRootView} from parent.
 *///w w  w  . j a  v a2s.  co  m
public static void onDestroy(ReactInfo reactInfo) {
    try {
        ReactRootView rootView = getRootView(reactInfo);
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
    } catch (Throwable e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:edu.ucsb.cs.cs185.inspirante.collections.DetailBlurDialog.java

public static void sendViewToBack(final View child) {
    final ViewGroup parent = (ViewGroup) child.getParent();
    if (parent != null) {
        parent.removeView(child);
        parent.addView(child, 0);// w  ww . j  ava2 s  .  c  o m
    }
}

From source file:cc.metapro.openct.utils.ActivityUtils.java

public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder,
        @NonNull final View view) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);
    }//w ww . j a  v  a2  s.  c  o  m

    ScrollView scrollView = new ScrollView(builder.getContext());
    scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    scrollView.addView(view);

    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            InputMethodManager imm = (InputMethodManager) builder.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    });

    AlertDialog dialog = builder.setView(scrollView).create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    return dialog;
}

From source file:jp.wasabeef.blurry.Blurry.java

public static void delete(ViewGroup target) {
    View view = target.findViewWithTag(TAG);
    if (view != null) {
        target.removeView(view);
    }//from  w  ww.java  2 s  . c o  m
}

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   ww w . j a  v a 2 s .  c om*/

    wrapper.addView(view);
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static void removeSearchViewSearchIcon(@Nullable View view) {
    if (view != null) {
        ImageView searchIcon = (ImageView) view;
        ViewGroup linearLayoutSearchView = (ViewGroup) view.getParent();
        if (linearLayoutSearchView != null) {
            linearLayoutSearchView.removeView(searchIcon);
            linearLayoutSearchView.addView(searchIcon);

            searchIcon.setAdjustViewBounds(true);
            searchIcon.setMaxWidth(0);//from   w  w  w  . j a  v  a2  s  . c o m
            searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            searchIcon.setImageDrawable(null);
        }
    }
}

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);
    parent.addView(toAdd, childIndex > -1 ? childIndex : defaultIndex);
}

From source file:android.support.design.testutils.TestUtilsActions.java

/**
 * Replaces an existing {@link TabLayout} with a new one inflated from the specified
 * layout resource.//from  ww  w.  ja v a  2s . c o  m
 */
public static ViewAction replaceTabLayout(final @LayoutRes int tabLayoutResId) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Replace TabLayout";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            final ViewGroup viewGroup = (ViewGroup) view;
            final int childCount = viewGroup.getChildCount();
            // Iterate over children and find TabLayout
            for (int i = 0; i < childCount; i++) {
                View child = viewGroup.getChildAt(i);
                if (child instanceof TabLayout) {
                    // Remove the existing TabLayout
                    viewGroup.removeView(child);
                    // Create a new one
                    final LayoutInflater layoutInflater = LayoutInflater.from(view.getContext());
                    final TabLayout newTabLayout = (TabLayout) layoutInflater.inflate(tabLayoutResId, viewGroup,
                            false);
                    // Make sure we're adding the new TabLayout at the same index
                    viewGroup.addView(newTabLayout, i);
                    break;
                }
            }

            uiController.loopMainThreadUntilIdle();
        }
    };
}

From source file:fr.shywim.antoinedaniel.utils.Utils.java

/**
 * Second part of the click animation.//from  ww  w  . j  ava  2 s .c  o  m
 *
 * @param v View who will have the effect.
 * @param isRoot Whether the passed view is the ViewGroup parent.
 */
public static void clickAnimUp(View v, boolean isRoot) {
    RelativeLayout root;
    if (isRoot)
        root = (RelativeLayout) v;
    else
        root = (RelativeLayout) v.getParent();
    final View rectView = root.findViewById(R.id.rect_view_id);
    if (rectView != null) {
        AlphaAnimation rectAnim = new AlphaAnimation(0.4f, 0f);
        rectAnim.setFillAfter(true);
        rectAnim.setInterpolator(new DecelerateInterpolator());
        rectAnim.setDuration(150);
        rectAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        ViewGroup parent = (ViewGroup) rectView.getParent();
                        rectView.setVisibility(View.GONE);
                        if (parent != null)
                            parent.removeView(rectView);
                    }
                });
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        rectView.clearAnimation();
        rectView.startAnimation(rectAnim);
    }
}

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);
    parent.addView(replaceWith, index);/*from w w w  .  j a  va 2 s  .  c  om*/
}