{"record":{"id":"0fe43562c31cffbf","repo":"scwang90/SmartRefreshLayout","slug":"3-view-most-only-support-three-sub-view","errorCode":null,"errorMessage":"最多只支持3个子View，Most only support three sub view","messagePattern":"最多只支持3个子View，Most only support three sub view","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java","lineNumber":347,"sourceCode":"            mEnableLoadMore = true;\n        }\n\n        ta.recycle();\n    }\n    //</editor-fold>\n\n    //<editor-fold desc=\"生命周期 life cycle\">\n\n    /**\n     * 重写 onFinishInflate 来完成 smart 的特定功能\n     * 1.智能寻找 Xml 中定义的 Content、Header、Footer\n     */\n    @Override\n    protected void onFinishInflate() {\n        super.onFinishInflate();\n        final int count = super.getChildCount();\n        if (count > 3) {\n            throw new RuntimeException(\"最多只支持3个子View，Most only support three sub view\");\n        }\n\n        int contentLevel = 0; // 当前找到内容布局的级别（0还没找到 1普通内容 2可滚动内容）\n        int indexContent = -1; // 内容布局所在的序号\n        for (int i = 0; i < count; i++) {\n            View view = super.getChildAt(i);\n            if (SmartUtil.isContentView(view) && (contentLevel < 2 || i == 1)) {\n                // 可滚动内容\n                indexContent = i;\n                contentLevel = 2; // 标记为可滚动内容，不会再被替换\n            } else if (!(view instanceof RefreshComponent) && contentLevel < 1) {\n                // 普通内容\n                indexContent = i;\n                contentLevel = i > 0 ? 1 : 0; // 如果是第一个标记为：未找到（第一个有可能是自定义Header），否则标记为：普通内容\n            }\n        }\n\n        int indexHeader = -1;","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/scwang90/SmartRefreshLayout/blob/224db48f8af897a930b810a6b6fc55af8cef0d57/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java#L329-L365","documentation":"SmartRefreshLayout.onFinishInflate() throws immediately when the XML layout declares more than 3 direct children of the <com.scwang.smart.refresh.layout.SmartRefreshLayout> tag. The widget reserves its child slots for exactly one header, one content view, and one footer, so any fourth direct child is a layout-authoring error and fails fast at inflate time rather than silently misbehaving.","triggerScenarios":"Placing 4+ views directly inside <SmartRefreshLayout> in XML, e.g. two content views, a header, and a footer, or putting a toolbar plus a RecyclerView plus extra banners as siblings instead of wrapping them in a single content ViewGroup.","commonSituations":"Developers new to SmartRefreshLayout treating it like a FrameLayout/LinearLayout and stacking multiple children; refactoring a layout and forgetting to wrap non-refresh content into the single content container; adding a loading overlay or empty-state view as a direct child of the refresh layout.","solutions":["Keep exactly one content child: wrap all your content views (toolbar, RecyclerView, overlays) in a single FrameLayout/CoordinatorLayout inside SmartRefreshLayout.","Verify in the layout XML that direct children are only: optional header, one content view, optional footer.","Headers/footers that need multiple views should be a single custom view implementing RefreshHeader/RefreshFooter, not multiple children.","Use RefreshHeader/RefreshFooter classes or ClassicsHeader/ClassicsFooter for header/footer slots instead of extra plain views."],"exampleFix":"<!-- before -->\n<SmartRefreshLayout ...>\n    <TextView .../>      <!-- header-ish -->\n    <RecyclerView .../>\n    <TextView .../>      <!-- footer-ish -->\n    <ProgressBar .../>   <!-- 4th child -> crash -->\n</SmartRefreshLayout>\n\n<!-- after -->\n<SmartRefreshLayout ...>\n    <RecyclerView .../>  <!-- the single content view -->\n    <FrameLayout ...>    <!-- wrap overlays inside a content container -->\n        <ProgressBar .../>\n    </FrameLayout> <!-- NO: still 2 children; instead put ProgressBar INSIDE the content or use footer slot -->\n</SmartRefreshLayout>","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the child-slot model: SmartRefreshLayout accepts at most 3 direct children (header, content, footer).","Always wrap multi-view content (toolbar + list + overlay) in a single ViewGroup as the content child.","Run the layout after every XML edit; this error fails fast at inflate time so it is caught by a simple preview/render.","Use design-time previews or tools:listitem checks to confirm the hierarchy before build."],"tags":["android","xml-layout","smartrefreshlayout","view-hierarchy","configuration"],"backgroundTag":null,"analyzedSha":"224db48f8af897a930b810a6b6fc55af8cef0d57","analyzedAt":"2026-08-14T10:09:28.455Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}