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:
NestedScrollView
?The Android docs say:
When the input method appears on the screen, it reduces the amount of space available for your app's UI. The system makes a decision as to how it should adjust the visible portion of your UI, but it might not get it right. To ensure the best behavior for your app, you should specify how you'd like the system to display your UI in the remaining space.
This could be an instance of the instability that is referenced.
It looks to me that this isn't an issue with NestedScrollView
and ScrollView
but is more of an issue with how the Activity is adjusting the UI based on the keyboard. The only difference between NestedScrollView
and ScrollView
is that NestedScrollView
has be ability to be both parent and child. I think that this highlights why you should follow the above advice where it says:
To ensure the best behavior for your app, you should specify how you'd like the system to display your UI in the remaining space.
ie using android:windowSoftInputMode="adjustResize"
always, rather than just when it is needed.
The problem here is not Nested Scroll-view, the problem is Android's Auto adjustment of view when keyboard appears/disappears on Input method's call. I hope you'll understand the problem in the link given below:
https://developer.android.com/training/keyboard-input/visibility.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With