How to keep a bottom nav bar from being pushed up on keyboard shown

后端 未结 5 2088
野的像风
野的像风 2021-02-03 20:20

How can i create a sticky footer that wont be moved up with the view when the softkey keyboard popups up?

Below is an image example of my current setup and what i want

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-03 21:18

    I've come across a pretty similar problem with the differences that a) I wasn't using a ScrollView at first and b) the item I didn't want to move was a simple TextView.

    Here's the answer I found: click

    What I did to fix it:

    • Use adjustResize
    • Use 4 Layouts: A surrounding one, 1 for the header, the ScrollView and 1 for your "bottom nav"
    • Don't just rely on android:layout_alignParentBottom="true", while this will move your navigation bar to the bottom of the screen, it also means that the keyboard can move it up because of "adjustResize"
    • Additionally use android:layout_height="wrap_content" in combination with android:layout_below="@id/MyScrollView" (so the layout will use up all the space it can get between the ScrollView and the bottom of the screen) and android:gravity="bottom" to simply have everything at the bottom of the layout.
    • You might also be able to use android:layout_height="match_parent" instead of android:layout_alignParentBottom="true" and android:layout_height="wrap_content" but I didn't fully test it like that.
    • Like I said, this will make the "bottom nav" layout use up all the space it can get below the ScrollView. If you don't want that, e.g. because your "bottom nav" has a different color you don't want to be shown too much, try creating a surrounding RelativeLayout for "bottom nav" and another empty layout inside that can push "bottom nav" downwards. ;)

提交回复
热议问题