yarolegovich / SlidingRootNav

DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.
Apache License 2.0
3.06k stars 455 forks source link

Fatal Exception: java.lang.IllegalArgumentException parameter must be a descendant of this view #103

Open theoyuncu8 opened 11 months ago

theoyuncu8 commented 11 months ago

Hello, there is an error here but I couldn't figure out how... I made some changes to the code but I still couldn't figure it out. @yarolegovich @jonathan-caryl @antonKozyriatskyi

@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (getChildCount() == 0) { addView(rootView); } for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if (child == rootView) { int rootLeft = positionHelper.getRootLeft(dragProgress, maxDragDistance); child.layout(rootLeft, top, rootLeft + (right - left), bottom); // 101. line } else { child.layout(left, top, right, bottom); } } }

/////

android.view.ViewGroup.offsetRectBetweenParentAndChild (ViewGroup.java:6351) android.view.ViewGroup.offsetDescendantRectToMyCoords (ViewGroup.java:6280) androidx.core.widget.NestedScrollView.isWithinDeltaOfScreen (NestedScrollView.java:1580) androidx.core.widget.NestedScrollView.onSizeChanged (NestedScrollView.java:2135) android.view.View.sizeChange (View.java:23223) android.view.View.setFrame (View.java:23173) android.view.View.layout (View.java:23030) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild (HeaderScrollingViewBehavior.java:149) com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:43) androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout (CoordinatorLayout.java:918) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.RelativeLayout.onLayout (RelativeLayout.java:1103) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) androidx.constraintlayout.widget.ConstraintLayout.onLayout (ConstraintLayout.java:1873) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) com.example.slidingrootnav.SlidingRootNavLayout.onLayout (SlidingRootNavLayout.java:101) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829) android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673) android.widget.LinearLayout.onLayout (LinearLayout.java:1582) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829) android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673) android.widget.LinearLayout.onLayout (LinearLayout.java:1582) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) com.android.internal.policy.DecorView.onLayout (DecorView.java:804) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.view.ViewRootImpl.performLayout (ViewRootImpl.java:3601) android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:3069) android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2070) android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8402) android.view.Choreographer$CallbackRecord.run (Choreographer.java:1058) android.view.Choreographer.doCallbacks (Choreographer.java:880) android.view.Choreographer.doFrame (Choreographer.java:813) android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1043) android.os.Handler.handleCallback (Handler.java:938) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loop (Looper.java:236) android.app.ActivityThread.main (ActivityThread.java:8037) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:656) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:967)

theoyuncu8 commented 11 months ago

android.view.ViewGroup.offsetRectBetweenParentAndChild (ViewGroup.java:6351) android.view.ViewGroup.offsetDescendantRectToMyCoords (ViewGroup.java:6280) androidx.core.widget.NestedScrollView.isWithinDeltaOfScreen (NestedScrollView.java:1580) androidx.core.widget.NestedScrollView.onSizeChanged (NestedScrollView.java:2135) android.view.View.sizeChange (View.java:23223) android.view.View.setFrame (View.java:23173) android.view.View.layout (View.java:23030) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild (HeaderScrollingViewBehavior.java:149) com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:43) androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout (CoordinatorLayout.java:918) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.RelativeLayout.onLayout (RelativeLayout.java:1103) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) androidx.constraintlayout.widget.ConstraintLayout.onLayout (ConstraintLayout.java:1873) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) com.example.slidingrootnav.SlidingRootNavLayout.onLayout (SlidingRootNavLayout.java:101) // Hi there!!!! android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829) android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673) android.widget.LinearLayout.onLayout (LinearLayout.java:1582) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829) android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673) android.widget.LinearLayout.onLayout (LinearLayout.java:1582) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.widget.FrameLayout.layoutChildren (FrameLayout.java:332) android.widget.FrameLayout.onLayout (FrameLayout.java:270) com.android.internal.policy.DecorView.onLayout (DecorView.java:804) android.view.View.layout (View.java:23033) android.view.ViewGroup.layout (ViewGroup.java:6468) android.view.ViewRootImpl.performLayout (ViewRootImpl.java:3601) android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:3069) android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2070) android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8402) android.view.Choreographer$CallbackRecord.run (Choreographer.java:1058) android.view.Choreographer.doCallbacks (Choreographer.java:880) android.view.Choreographer.doFrame (Choreographer.java:813) android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1043) android.os.Handler.handleCallback (Handler.java:938) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loop (Looper.java:236) android.app.ActivityThread.main (ActivityThread.java:8037) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:656) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:967)

theoyuncu8 commented 11 months ago
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (getChildCount() == 0) {
        addView(rootView);
    }
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        if (child == rootView) {
            int rootLeft = positionHelper.getRootLeft(dragProgress, maxDragDistance);
            child.layout(rootLeft, top, rootLeft + (right - left), bottom);   // 101. line
        } else {
            child.layout(left, top, right, bottom);
        }
    }
}
theoyuncu8 commented 10 months ago

@yarolegovich Please help me!