<?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2015 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. -->
*/ @RestrictTo(LIBRARY_GROUP) public static final class SnackbarLayout extends BaseTransientBottomBar.SnackbarBaseLayout { public SnackbarLayout(Context context) { super(context); }
public SnackbarLayout(Context context, AttributeSet attrs) { super(context, attrs); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // Work around our backwards-compatible refactoring of Snackbar and inner content // being inflated against snackbar's parent (instead of against the snackbar itself). // Every child that is width=MATCH_PARENT is remeasured again and given the full width // minus the paddings. int childCount = getChildCount(); int availableWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child.getLayoutParams().width == ViewGroup.LayoutParams.MATCH_PARENT) { child.measure( MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY)); } } } }
在snackabar的父类 BaseTransientBottomBar void onViewHidden(int event) { // First tell the SnackbarManager that it has been dismissed SnackbarManager.getInstance().onDismissed(managerCallback); if (callbacks != null) { // Notify the callbacks. Do that from the end of the list so that if a callback // removes itself as the result of being called, it won't mess up with our iteration int callbackCount = callbacks.size(); for (int i = callbackCount - 1; i >= 0; i--) { callbacks.get(i).onDismissed((B) this, event); } } // Lastly, hide and remove the view from the parent (if attached) ViewParent parent = view.getParent(); if (parent instanceof ViewGroup) { ((ViewGroup) parent).removeView(view); } } 方法中,参数为3, ,可移除handler.