Scroll vertically through the whole view when the soft keyboard is shown

I'm working on a screen that has a LinearLayout with a TableLayout inside, in order to show texts, some EditTexts and some buttons.

The problem is that on the smartphone, when I click on a EditText that is on the top of the layout, a button that is on the bottom hides behind the soft keyboard. The only way to make the button appear again is to hide the soft keyboard.

在这里输入图像描述

Is it possible to make my layout on top of the soft keyboard to scroll to the button of my view, so the user can see the soft keyboard and the bottom on the button?

I tried to use a ScrollView around the TableLayout, but it does not scroll to the button of my layout, so the user can not see to bottom.

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.


I have a similar view and it runs 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 height as I put on each layout. And if not success, I think the problem is TableLayout , try not using it as I do.


android:windowSoftInputMode="stateVisible|adjustPan"到您的活动标记中应该可以完成工作。


  • try android:windowSoftInputMode="adjustResize"
  • if the scrollView has sibling view element, try this on ScrollView

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

  • 链接地址: http://www.djcxy.com/p/93040.html

    上一篇: 在软键盘前显示视图

    下一篇: 显示软键盘时,在整个视图中垂直滚动