I've got this layout:
Without colors: https://i.sstatic.net/OdSda.png
What I want to happen if I click on the EditText next to D and the keyboard opens up:
What's actually happening:
Two things I've already tried but with both didn't fully work as expected:
I) Add android:windowSoftInputMode="adjustPan"
to the manifest:
II) Add android:windowSoftInputMode="adjustResize"
to the manifest: Nothing changes unless I also add android:fitsSystemWindows="true"
to the tab fragment's xml:
I managed to find a way! :) A big thanks goes to Umair for giving me the tip with the ScrollView and testing different things too!
First of all, this is how the overall layout is built now:
android:fitsSystemWindows="true"
- the ScrollView seems to disable that anyway!)
Manifest:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
....
Code for RelativeLayout 4:
Before:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom">
<TextView
android:id="@+id/textE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/E"
android:textSize="20sp"/>
</RelativeLayout>
After:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_below="@id/ScrollViewABCD"
android:gravity="bottom">
<TextView
android:id="@+id/textE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/E"
android:textSize="20sp"/>
</RelativeLayout>
I'm not sure if android:layout_gravity="bottom"
is actually needed anymore (android:gravity="bottom"
is to have the text at the bottom!) but I haven't noticed any changes without it either.
android:layout_alignParentBottom="true"
is the important part here because without it, Relative Layout 4 would be simply below the ScrollView but this little extra makes it use up all the space it can, while still keeping it as far south as possible. Plus, you can still use margins to create some empty space between the ScrollView and RL 4 (even though you're only going to see it in the Preview window in Android Studio).
What this does:
android:fitsSystemWindows="true"
)