I just observed the following behavior on my Nexus 9 with Android 7.1.1 and Android Support Library 25.3.1.
Here is my activity's layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:paddingBottom="4dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#fffaaa" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#bbbaaa" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#f00" />
</LinearLayout>
</ScrollView>
This is how it looks on the screen:
When the on-screen keyboard shows up, the system resizes my activity's layout so it takes up the space from the top of the screen to the keyboard. Please consider the dashed red line in the screenshot below:
However, when I replace the ScrollView
with a NestedScrollView
, the system doesn't resize the layout:
Now the dashed red line is below the keyboard. The issue can easily be fixed by applying android:windowSoftInputMode="adjustResize"
to the activity:
The red dashed line is above the keyboard now. My questions are:
- Why do I observe such a behavior?
- What's wrong with
NestedScrollView
?