Activity with fragments does not resize when the keyboard opens

前端 未结 7 1604
挽巷
挽巷 2020-12-08 04:38

In my main activity there is a RelativeLayout that has 2 childs:

  • An ImageView which serves as the background
  • A LinearLa
7条回答
  •  执念已碎
    2020-12-08 05:18

    When the soft keyboard appears on the screen, the amount of space available for the application's UI reduces. The system makes decision on how to organize the available space between the application's UI and soft keyboard.

    • If the window content contains ListView, ScrollView, the application's window is resized provided all the content is visible.
    • If re-sizing is not feasible, pan and scan approach is used, which simply involves scrolling the application's window so that the currently focused view is visible.

    Since your layout does not contain any ListView, ScrollView, re-sizing is ruled out.

    The window's root view is a FrameLayout to which you were originally adding LinearLayout. Since LinearLayout does not support scrolling, pan and scan approach is also ruled out. Hence wrapping the layout inside ScrollView solves the scrolling issue.

    You can refer Android Developers blog for more details.

    Update 1:

    OP was able to solve the issue, as indicated in this answer. The issue was happening due to one fragment overlaying another fragment after animation and the parent of these Fragment's was a LinearLayout. For overlay purpose, you need to use RelativeLayout or FrameLayout only.

提交回复
热议问题