use of android.support.design.widget.CoordinatorLayout.LayoutParams 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);
}
use of android.support.design.widget.CoordinatorLayout.LayoutParams in project RxBinding by JakeWharton.
the class SwipeDismissBehaviorObservable method subscribeActual.
@Override
protected void subscribeActual(Observer<? super View> observer) {
if (!checkMainThread(observer)) {
return;
}
if (!(view.getLayoutParams() instanceof LayoutParams)) {
throw new IllegalArgumentException("The view is not in a Coordinator Layout.");
}
LayoutParams params = (LayoutParams) view.getLayoutParams();
final SwipeDismissBehavior behavior = (SwipeDismissBehavior) params.getBehavior();
if (behavior == null) {
throw new IllegalStateException("There's no behavior set on this view.");
}
Listener listener = new Listener(behavior, observer);
observer.onSubscribe(listener);
behavior.setListener(listener);
}
Aggregations