Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView padding ignored on keyboard show

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

like image 547
pavelkorolevxyz Avatar asked Nov 01 '19 10:11

pavelkorolevxyz


1 Answers

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>
like image 142
swati vishnoi Avatar answered Oct 10 '22 04:10

swati vishnoi