When the keyboard is shown the whole layout is squashed because there is less space available. All you have to do is align the LinearLayout
to the bottom of the screen and it will be displayed directly above the keyboard. You could for example use a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="60dp"
android:clipToPadding="false">
<RelativeLayout
android:id="@+id/rlContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
... // The content of your layout goes here
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="@+id/llFooter"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
// This LinearLayout will be aligned to the
// bottom of the screen and displayed above your keyboard
</LinearLayout>
</RelativeLayout>
The ScrollView
is just there to make your layout scrollable when the keyboard opens and there isn't enough room anymore to display all of it at once. The LinearLayout
at the bottom will be positioned independently at the bottom of the screen and overlap anything else.
The ScrollView
also has a padding which is equal to the size of the footer View
and has clipToPadding
set to false
. This means the ScrollView
can use paddings to display content. You need this or otherwise the bottom part of your layout would be hidden behind the LinearLayout
at the bottom. You can make the LinearLayout
a little transparent for a nice effect when scrolling.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…