Example usage for android.view View getParent

List of usage examples for android.view View getParent

Introduction

In this page you can find the example usage for android.view View getParent.

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:Main.java

public static View findParentViewById(View view, int id) {
    ViewParent viewParent = view.getParent();

    while (viewParent != null && viewParent instanceof View) {
        View parentView = (View) viewParent;
        if (parentView.getId() == id)
            return parentView;

        viewParent = parentView.getParent();
    }/*from  w w  w . j  a  v a2s.  com*/

    return null;
}

From source file:Main.java

public static ViewGroup getParent(View v, int parentId) {
    ViewGroup p = (ViewGroup) v.getParent();
    while (true) {
        if (p == null) {
            return null;
        }//from www.  j av a  2  s .  c  o m
        if (p.getId() == parentId) {
            return p;
        }
        p = (ViewGroup) p.getParent();
    }
}

From source file:Main.java

public static void removeSelf(View child) {
    if (null == child)
        return;//from   ww  w.j  a va2  s.c  o m
    if (child.getParent() instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) child.getParent();
        if (null != parent)
            parent.removeView(child);
    }
}

From source file:Main.java

public static void removeSelfFromParent(View child) {
    if (child != null) {
        ViewParent parent = child.getParent();
        if (parent != null && parent instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) parent;
            group.removeView(child);/*w w  w  .j a  v a 2s .c  om*/
        }
    }
}

From source file:Main.java

public static void requestLayoutParent(View view, boolean isAll) {
    ViewParent parent = view.getParent();
    while (parent != null && parent instanceof View) {
        if (!parent.isLayoutRequested()) {
            parent.requestLayout();//from   w w  w. j  a v  a  2 s . co m
            if (!isAll) {
                break;
            }
        }
        parent = parent.getParent();
    }
}

From source file:Main.java

public static void removeSelfFromParent(View child) {
    if (child != null) {
        ViewParent parent = child.getParent();
        if (parent != null && parent instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) parent;
            viewGroup.removeView(child);
        }/*  w  w w .  j av  a2 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  w w  w  .  j  a v a2s .com*/

    wrapper.addView(view);
}

From source file:Main.java

public static void removeSelfFromParent(View child) {

    if (child != null) {

        ViewParent parent = child.getParent();

        if (parent instanceof ViewGroup) {

            ViewGroup group = (ViewGroup) parent;

            group.removeView(child);//from w  w w. j av  a  2s  . co m
        }
    }
}

From source file:Main.java

public static void removeSelfFromParent(View view) {
    if (view != null) {
        ViewParent parent = view.getParent();
        if (parent != null && parent instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) parent;
            group.removeView(view);/*from w w  w.  j  a va  2 s.  c o  m*/
        }
    }
}

From source file:Main.java

/**
 * @param top//from   w  w w.jav  a  2 s  . co m
 * @param left
 * @param bottom
 * @param right
 * @param delegate
 */
public static void increaseHitRectBy(final int top, final int left, final int bottom, final int right,
        final View delegate) {
    final View parent = (View) delegate.getParent();
    if (parent != null && delegate.getContext() != null) {
        parent.post(new Runnable() {
            // Post in the parent's message queue to make sure the parent
            // lays out its children before we call getHitRect()
            public void run() {
                final float densityDpi = delegate.getContext().getResources().getDisplayMetrics().densityDpi;
                final Rect r = new Rect();
                delegate.getHitRect(r);
                r.top -= transformToDensityPixel(top, densityDpi);
                r.left -= transformToDensityPixel(left, densityDpi);
                r.bottom += transformToDensityPixel(bottom, densityDpi);
                r.right += transformToDensityPixel(right, densityDpi);
                parent.setTouchDelegate(new TouchDelegate(r, delegate));
            }
        });
    }
}