In Android Studio after starting a new project, and selecting a Tabbed Activity, after the project is build, I get this error in the Android Monitor:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 23581
java.lang.IllegalArgumentException: Rect should intersect with child's bounds.
at android.support.design.widget.CoordinatorLayout.offsetChildByInset(CoordinatorLayout.java:1319)
at android.support.design.widget.CoordinatorLayout.onChildViewsChanged(CoordinatorLayout.java:1257)
at android.support.design.widget.CoordinatorLayout$OnPreDrawListener.onPreDraw(CoordinatorLayout.java:1805)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1867)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
What does this exception mean, and how to fix it? It is a completely new project, so I have not made any change.
After updating the new appcompat version to 24.2.1 i had the same bug, Try to lower the version to 24.1.1 or even to a stable 23 version.
In my case the problem was caused because of FloatingActionButton.Behavior.
Here the code inside coordinator layout
if (behavior != null && behavior.getInsetDodgeRect(this, child, rect)) {
// Make sure that it intersects the views bounds
if (!rect.intersect(child.getLeft(), child.getTop(),
child.getRight(), child.getBottom())) {
throw new IllegalArgumentException("Rect should intersect with child's bounds.");
}
}
And here the code inside of FloatingActionButton.Behavior
@Override
public boolean getInsetDodgeRect(@NonNull CoordinatorLayout parent,
@NonNull FloatingActionButton child, @NonNull Rect rect) {
// Since we offset so that any internal shadow padding isn't shown, we need to make
// sure that the shadow isn't used for any dodge inset calculations
final Rect shadowPadding = child.mShadowPadding;
rect.set(child.getLeft() + shadowPadding.left,
child.getTop() + shadowPadding.top,
child.getRight() - shadowPadding.right,
child.getBottom() - shadowPadding.bottom);
return true;
}
As you can see getInsetDodgeRect was returning true and by some reason rect was not intersecting. This causes the problem.
The workaround.
I could fix it just extending the behavior and overwriting the method getInsetDodgeRect to return false;
public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
...
@Override
public boolean getInsetDodgeRect(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton child, @NonNull Rect rect) {
super.getInsetDodgeRect(parent, child, rect);
return false;
}
...
It's a bug introduced in support library 24.2.1
, see here.
Known workarounds:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With