下面列出了android.view.View#removeOnLayoutChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** @hide */
protected void detachFromAnchor() {
final View anchor = getAnchor();
if (anchor != null) {
final ViewTreeObserver vto = anchor.getViewTreeObserver();
vto.removeOnScrollChangedListener(mOnScrollChangedListener);
anchor.removeOnAttachStateChangeListener(mOnAnchorDetachedListener);
}
final View anchorRoot = mAnchorRoot != null ? mAnchorRoot.get() : null;
if (anchorRoot != null) {
anchorRoot.removeOnAttachStateChangeListener(mOnAnchorRootDetachedListener);
anchorRoot.removeOnLayoutChangeListener(mOnLayoutChangeListener);
}
mAnchor = null;
mAnchorRoot = null;
mIsAnchorRootAttached = false;
}
@Override
public void onLayoutChange(final View v, final int left, final int top, final int right, final int bottom,
final int oldLeft, final int oldTop, final int oldRight, final int oldBottom) {
if (left == right) {
return;
}
final WeakReference<T> found = viewModelMap.get(v.hashCode());
if (found == null) {
v.removeOnLayoutChangeListener(this);
return;
}
final T urlProvider = found.get();
// Remove from map.
viewModelMap.delete(v.hashCode());
if (urlProvider != null) {
final String url = getUrl.apply(urlProvider);
loadImage((ImageView) v, url);
v.removeOnLayoutChangeListener(this);
}
}
void removeViewWithSubviewClippingEnabled(View view) {
Assertions.assertCondition(mRemoveClippedSubviews);
Assertions.assertNotNull(mClippingRect);
Assertions.assertNotNull(mAllChildren);
view.removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
int index = indexOfChildInAllChildren(view);
if (isChildInViewGroup(mAllChildren[index])) {
int childIndexOffset = 0;
for (int i = 0; i < index; i++) {
if (!isChildInViewGroup(mAllChildren[i])) {
childIndexOffset++;
}
}
super.removeViewsInLayout(index - childIndexOffset, 1);
}
removeFromArray(index);
}
private void cleanup() {
parent.getViewTreeObserver().removeOnPreDrawListener(this);
parent.removeOnAttachStateChangeListener(this);
int count = layoutChangeListenerMap.size();
if (count > 0) {
Collection<View> views = layoutChangeListenerMap.keySet();
for (View view : views) {
View.OnLayoutChangeListener listener = layoutChangeListenerMap.get(view);
view.removeOnLayoutChangeListener(listener);
}
layoutChangeListenerMap.clear();
}
}
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (view.isFocused() && view instanceof TextView) {
// A focused view changed its bounds. Follow it?
int height = bottom - top;
int oldHeight = oldBottom - oldTop;
if (oldHeight != height) {
zoomToView(view, false);
}
} else {
view.removeOnLayoutChangeListener(this);
}
}
/**
* Should be called when the view is detached from the screen.
*
* @see #setRelativeToView(View)
*/
public void detachView(@Nullable View view) {
if (view == null) {
return;
}
view.removeOnLayoutChangeListener(attachedViewLayoutChangeListener);
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (oldTop - top > Utils.dpToPx(96)) {
v.removeOnLayoutChangeListener(this);
scrollPostForReply(top);
}
}
private void finish(boolean immediate) {
mView.removeView(immediate);
mCallback.onDestroyActionMode(mMode);
mFinished = true;
mTarget.removeOnAttachStateChangeListener(this);
final View root = mTarget.getRootView();
root.removeOnLayoutChangeListener(this);
root.removeOnAttachStateChangeListener(this);
mTarget = null;
}
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
registerViewWithLifecycleOwner(view);
view.removeOnLayoutChangeListener(this);
}
void clear(View containerView) {
containerView.removeOnLayoutChangeListener(preventerListener);
preventerListener = null;
}
@Override
public void onLayoutChange(
View v,
int left,
int top,
int right,
int bottom,
int oldLeft,
int oldTop,
int oldRight,
int oldBottom) {
BottomAppBar child = viewRef.get();
// If the child BAB no longer exists, remove the listener.
if (child == null || !(v instanceof FloatingActionButton)) {
v.removeOnLayoutChangeListener(this);
return;
}
FloatingActionButton fab = ((FloatingActionButton) v);
fab.getMeasuredContentRect(fabContentRect);
int height = fabContentRect.height();
// Set the cutout diameter based on the height of the fab.
child.setFabDiameter(height);
CoordinatorLayout.LayoutParams fabLayoutParams =
(CoordinatorLayout.LayoutParams) v.getLayoutParams();
// Manage the bottomMargin of the fab if it wasn't explicitly set to something. This
// adds space below the fab if the BottomAppBar is hidden.
if (originalBottomMargin == 0) {
// Extra padding is added for the fake shadow on API < 21. Ensure we don't add too
// much space by removing that extra padding.
int bottomShadowPadding = (fab.getMeasuredHeight() - height) / 2;
int bottomMargin =
child
.getResources()
.getDimensionPixelOffset(R.dimen.mtrl_bottomappbar_fab_bottom_margin);
// Should be moved above the bottom insets with space ignoring any shadow padding.
int minBottomMargin = bottomMargin - bottomShadowPadding;
fabLayoutParams.bottomMargin = child.getBottomInset() + minBottomMargin;
fabLayoutParams.leftMargin = child.getLeftInset();
fabLayoutParams.rightMargin = child.getRightInset();
boolean isRtl = ViewUtils.isLayoutRtl(fab);
if (isRtl) {
fabLayoutParams.leftMargin += child.fabOffsetEndMode;
} else {
fabLayoutParams.rightMargin += child.fabOffsetEndMode;
}
}
}
private void dismissSheet(Runnable runAfterDismissThis) {
if (state == State.HIDDEN) {
runAfterDismiss = null;
return;
}
// This must be set every time, including if the parameter is null
// Otherwise a new sheet might be shown when the caller called dismiss after a showWithSheet call, which would be
runAfterDismiss = runAfterDismissThis;
final View sheetView = getSheetView();
sheetView.removeOnLayoutChangeListener(sheetViewOnLayoutChangeListener);
cancelCurrentAnimation();
ObjectAnimator anim = ObjectAnimator.ofFloat(this, SHEET_TRANSLATION, 0);
anim.setDuration(ANIMATION_DURATION);
anim.setInterpolator(animationInterpolator);
anim.addListener(new CancelDetectionAnimationListener() {
@Override
public void onAnimationEnd(Animator animation) {
if (!canceled) {
currentAnimator = null;
setState(State.HIDDEN);
setSheetLayerTypeIfEnabled(LAYER_TYPE_NONE);
final View view = getSheetView();
if (view != null)
removeView(view);
for (OnSheetDismissedListener onSheetDismissedListener : onSheetDismissedListeners)
onSheetDismissedListener.onDismissed(BottomSheetLayout.this);
// Remove sheet specific properties
viewTransformer = null;
onSheetDismissedListeners.clear();
onSheetStateChangeListeners.clear();
if (runAfterDismiss != null) {
runAfterDismiss.run();
runAfterDismiss = null;
}
}
}
});
anim.start();
currentAnimator = anim;
sheetStartX = 0;
sheetEndX = screenWidth;
}
private void dismissSheet(Runnable runAfterDismissThis) {
if (state == State.HIDDEN) {
runAfterDismiss = null;
return;
}
// This must be set every time, including if the parameter is null
// Otherwise a new sheet might be shown when the caller called dismiss after a showWithSheet call, which would be
runAfterDismiss = runAfterDismissThis;
final View sheetView = getSheetView();
sheetView.removeOnLayoutChangeListener(sheetViewOnLayoutChangeListener);
cancelCurrentAnimation();
ObjectAnimator anim = ObjectAnimator.ofFloat(this, SHEET_TRANSLATION, 0);
anim.setDuration(ANIMATION_DURATION);
anim.setInterpolator(animationInterpolator);
anim.addListener(new CancelDetectionAnimationListener() {
@Override
public void onAnimationEnd(Animator animation) {
if (!canceled) {
currentAnimator = null;
setState(State.HIDDEN);
setSheetLayerTypeIfEnabled(LAYER_TYPE_NONE);
removeView(sheetView);
for (OnSheetDismissedListener onSheetDismissedListener : onSheetDismissedListeners) {
onSheetDismissedListener.onDismissed(BottomSheetLayout.this);
}
// Remove sheet specific properties
viewTransformer = null;
if (runAfterDismiss != null) {
runAfterDismiss.run();
runAfterDismiss = null;
}
}
}
});
anim.start();
currentAnimator = anim;
sheetStartX = 0;
sheetEndX = screenWidth;
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this); // Unregister self.
addSearchFragment();
}