{"record":{"id":"03d9b732b64cf6e0","repo":"umano/AndroidSlidingUpPanel","slug":"gravity-must-be-set-to-either-top-or-bottom","errorCode":null,"errorMessage":"gravity must be set to either top or bottom","messagePattern":"gravity must be set to either top or bottom","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java","lineNumber":366,"sourceCode":"    }\n\n    /**\n     * Set the Drag View after the view is inflated\n     */\n    @Override\n    protected void onFinishInflate() {\n        super.onFinishInflate();\n        if (mDragViewResId != -1) {\n            setDragView(findViewById(mDragViewResId));\n        }\n        if (mScrollableViewResId != -1) {\n            setScrollableView(findViewById(mScrollableViewResId));\n        }\n    }\n\n    public void setGravity(int gravity) {\n        if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {\n            throw new IllegalArgumentException(\"gravity must be set to either top or bottom\");\n        }\n        mIsSlidingUp = gravity == Gravity.BOTTOM;\n        if (!mFirstLayout) {\n            requestLayout();\n        }\n    }\n\n    /**\n     * Set the color used to fade the pane covered by the sliding pane out when the pane\n     * will become fully covered in the expanded state.\n     *\n     * @param color An ARGB-packed color value\n     */\n    public void setCoveredFadeColor(int color) {\n        mCoveredFadeColor = color;\n        requestLayout();\n    }\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java#L348-L384","documentation":"SlidingUpPanelLayout supports only TOP or BOTTOM gravity; setGravity() validates the argument and throws IllegalArgumentException for anything else. The gravity determines whether the panel slides up from the bottom or down from the top.","triggerScenarios":"Calling setGravity() with a gravity value other than Gravity.TOP or Gravity.BOTTOM (e.g. Gravity.LEFT, Gravity.RIGHT, Gravity.CENTER, 0, or a combined flag).","commonSituations":"Developers reuse a gravity variable intended for a different widget (LinearLayout, WindowManager flags) which allows LEFT/RIGHT/CENTER, then pass it to this layout; or pass 0/unset constants from configuration.","solutions":["Pass only Gravity.TOP or Gravity.BOTTOM to setGravity()","Check the value being forwarded; it likely comes from another widget's gravity attribute","Instead of programmatic setGravity, use the XML attribute umanoScrollableView/panel-gravity style attr supported by the layout"],"exampleFix":"// before\nlayout.setGravity(Gravity.CENTER);\n// after\nlayout.setGravity(Gravity.BOTTOM); // or Gravity.TOP","handlingStrategy":"validation","validationCode":"int g = resolveGravity(someGravity);\nif (g != Gravity.TOP && g != Gravity.BOTTOM) g = Gravity.BOTTOM;\nlayout.setGravity(g);","typeGuard":"boolean isValidPanelGravity(int g) { return g == Gravity.TOP || g == Gravity.BOTTOM; }","tryCatchPattern":"try { layout.setGravity(g); } catch (IllegalArgumentException e) { layout.setGravity(Gravity.BOTTOM); }","preventionTips":["Only pass Gravity.TOP or Gravity.BOTTOM","Don't reuse gravity values from other widgets","Prefer XML attribute configuration"],"tags":["android","illegal-argument","gravity"],"backgroundTag":"invalid-argument-value","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}