Let's say I have this simple layout:
https://imgur.com/k6zuh3f
<?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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80dp"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
...
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Eighth" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:text="Button" />
</RelativeLayout>
Note there is paddingBottom
on ScrollView
with clipToPadding=false
. It's needed so Button
looks like floating button over scroll view content. ScrollView padding is used to make space below content to make last child available.
If the last child is EditText
I expect ScrollView
to scroll making EditText
visible over software keyboard. But it ends with this https://imgur.com/GwOtLIq
Kind of expected behavior can be achieved using layout_marginBottom
instead of paddingBottom
, but in this case obviously I can't see my content behind Button
. Screenshot https://imgur.com/oSC24qV
Is there a way to make ScrollView
to respect its paddings in terms of keyboard avoiding?
UPDATE: full xml code here https://pastebin.com/P8n0aZ2i
you just need to define soft-Input adjustment type in manifest for your activity . You can add following line in your manifest.
<activity android:name=".Main2Activity" android:theme="@style/BaseTheme_FullScreen2"
android:windowSoftInputMode="adjustResize|adjustPan">
</activity>
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