Search in sources :

Example 1 with CompositorViewHolderBehavior

use of org.chromium.chrome.browser.compositor.CompositorViewHolderBehavior in project AndroidChromium by JackyAndroid.

the class SnackbarView method addToParent.

private void addToParent() {
    // we create new LayoutParams every time.
    if (mParent instanceof CoordinatorLayout) {
        CoordinatorLayout.LayoutParams lp = new LayoutParams(getLayoutParams());
        lp.gravity = Gravity.BOTTOM | Gravity.START;
        lp.setBehavior(new CompositorViewHolderBehavior());
        mParent.addView(mView, lp);
    } else if (mParent instanceof FrameLayout) {
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getLayoutParams());
        lp.gravity = Gravity.BOTTOM | Gravity.START;
        mParent.addView(mView, lp);
    } else {
        assert false : "Only FrameLayout and CoordinatorLayout are supported to show snackbars";
    }
    // Why setting listener on parent? It turns out that if we force a relayout in the layout
    // change listener of the view itself, the force layout flag will be reset to 0 when
    // layout() returns. Therefore we have to do request layout on one level above the requested
    // view.
    mParent.addOnLayoutChangeListener(mLayoutListener);
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.support.design.widget.CoordinatorLayout.LayoutParams) LayoutParams(android.support.design.widget.CoordinatorLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) CompositorViewHolderBehavior(org.chromium.chrome.browser.compositor.CompositorViewHolderBehavior)

Aggregations

CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 LayoutParams (android.support.design.widget.CoordinatorLayout.LayoutParams)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 FrameLayout (android.widget.FrameLayout)1 CompositorViewHolderBehavior (org.chromium.chrome.browser.compositor.CompositorViewHolderBehavior)1