下面列出了android.view.View#dispatchApplyWindowInsets ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
StatusBarView statusBarView = findViewById(R.id.scene_status_bar);
if (statusBarView != null) {
if (statusBarView.getParent() != this) {
throw new IllegalStateException("StatusBarView parent must be " + getClass().getSimpleName());
}
insets = statusBarView.dispatchApplyWindowInsets(insets);
}
if (insets.isConsumed()) {
return insets;
}
NavigationBarView navigationBarView = findViewById(R.id.scene_navigation_bar);
if (navigationBarView != null) {
if (navigationBarView.getParent() != this) {
throw new IllegalStateException("NavigationBarView parent must be " + getClass().getSimpleName());
}
insets = navigationBarView.dispatchApplyWindowInsets(insets);
}
if (insets.isConsumed()) {
return insets;
}
final int count = getChildCount();
for (int i = 0; i < count; i++) {
View childView = getChildAt(i);
if (childView == statusBarView || childView == navigationBarView) {
continue;
}
insets = childView.dispatchApplyWindowInsets(insets);
if (insets.isConsumed()) {
break;
}
}
return insets;
}
@SuppressLint("NewApi")
private void dispatchChildInsets(View child, Object insets, int drawerGravity)
{
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT)
{
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
}
else if (drawerGravity == Gravity.RIGHT)
{
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
@SuppressLint("NewApi")
private void dispatchChildInsets(View child, Object insets, int drawerGravity)
{
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT)
{
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
}
else if (drawerGravity == Gravity.RIGHT)
{
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
public static WindowInsetsCompat dispatchApplyWindowInsets(View v, WindowInsetsCompat insets) {
if (!(insets instanceof WindowInsetsCompatApi21)) {
return insets;
}
WindowInsets unwrapped = ((WindowInsetsCompatApi21) insets).unwrap();
WindowInsets result = v.dispatchApplyWindowInsets(unwrapped);
if (result != unwrapped) {
return new WindowInsetsCompatApi21(result);
}
return insets;
}
public static void dispatchChildInsets(View child, Object insets, int gravity) {
WindowInsets wi = (WindowInsets) insets;
if (gravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (gravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
@Override
public void dispatchChildInsets(View child, Object insets, int drawerGravity) {
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (drawerGravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
public static void dispatchChildInsets(View child, Object insets, int gravity) {
WindowInsets wi = (WindowInsets) insets;
if (gravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (gravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
public static void dispatchChildInsets(View child, Object insets, int gravity) {
WindowInsets wi = (WindowInsets) insets;
if (gravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (gravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
@SuppressLint("NewApi")
private void dispatchChildInsets(View child, Object insets, int drawerGravity) {
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (drawerGravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
public static void dispatchChildInsets(View child, Object insets, int gravity) {
WindowInsets wi = (WindowInsets) insets;
if (gravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (gravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (insets != null) {
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
View child = getChildAt(i);
child.dispatchApplyWindowInsets(insets);
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@SuppressLint("NewApi")
private void dispatchChildInsets(View child, Object insets, int drawerGravity) {
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
} else if (drawerGravity == Gravity.RIGHT) {
wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
}
child.dispatchApplyWindowInsets(wi);
}