Scroll vertically through the entire view when the soft keyboard is displayed

I work on screen with LinearLayout with TableLayout inside to show texts, some EditTexts and some buttons.

The problem is that on the smartphone, when I click on EditText, which is located at the top of the layout, the button that is at the bottom is hidden behind the soft keyboard. The only way to turn on the button again is to hide the soft keyboard.

enter image description here

Can I make my layout on top of the soft keyboard to go to the button of my view so that the user can see the soft keyboard and the bottom of the button?

I tried using ScrollView around TableLayout, but it does not scroll to the button of my layout, so the user cannot see from below.

This is my layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/linearLayoutMain" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="vertical" > <include layout="@layout/login_container"/> <LinearLayout android:orientation="horizontal" android:background="@drawable/_grey_rounded_bottom" android:layout_width="match_parent" android:layout_height="30dp"/> </LinearLayout> </ScrollView> </LinearLayout> 

Thanks in advance.

+4
source share
3 answers

I have a similar look and it works for me. See my code:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" tools:context=".MainActivity" android:orientation="vertical" > <LinearLayout ... /> <!--Have an image that I want to stay on the top --> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" ... > <RelativeLayout ... > <!-- EditText of username and EditText of password and a CheckBox --> <LinearLayout android:id="@+id/linearLayoutEntrar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/checkBoxRecordarDatos" android:gravity="center" android:layout_marginTop="7dp" android:weightSum="1.0"> <Button android:id="@+id/buttonEntrar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:text="@string/login_entrar" android:textColor="@android:color/white" android:textStyle="bold" android:textSize="@dimen/textSize" android:onClick="entrar" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayoutJugar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/linearLayoutEntrar" android:layout_marginTop="7dp" android:gravity="center" android:weightSum="1.0" > <Button android:id="@+id/buttonJugar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:onClick="jugar" android:text="@string/login_jugar" android:textColor="@android:color/white" android:textSize="@dimen/textSize" android:textStyle="bold" /> </LinearLayout> </RelativeLayout> </ScrollView> </LinearLayout> 

Try changing the height as I impose on each layout. And if not success, I think the problem is TableLayout , do not use it like me.

0
source

Adding android:windowSoftInputMode="stateVisible|adjustPan" to your activity tag in the manifest should do the job.

0
source
  • try android: windowSoftInputMode = "adjustResize"
  • If scrollView has a sibling view element, try this in ScrollView

    Android: layout_width = "match_parent" android: layout_height = "0dp" Android: layout_weight = "1"

0
source

Source: https://habr.com/ru/post/1490671/


All Articles