Can not get ScrollView to scroll when soft keyboard is shown

后端 未结 2 511
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 01:13

I have been trying to get this scrollview to scroll, and have not had any luck in doing so. I have tried many types of fixes but cant seem to get one working. I would like t

相关标签:
2条回答
  • 2020-12-16 01:26

    Add android:windowSoftInputMode="adjustResize" to the <activity> tag in your AndroidManifest.xml. This will cause the screen to be resized to the space left over after the software keyboard is shown. As a result, you will be able to scroll, since the screen will not be covered by the keyboard in any way.

    EDIT:

    I have written a minimal example and tested it. Unless there is a huge misunderstanding, try this code and then figure out why yours doesn't work:

    xml layout:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        >
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
    
            <TextView
                android:layout_height="2000dp"
                android:layout_width="wrap_content"
                android:gravity="top"
                android:text="Scroll Down!"/>
    
            <EditText
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:hint="Enter Text"
                />
        </LinearLayout>
    </ScrollView>
    

    manifest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.example"
              android:versionCode="1"
              android:versionName="1.0">
        <uses-sdk android:minSdkVersion="15"/>
        <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
            <activity android:name="MyActivity"
                      android:label="@string/app_name"
                    android:windowSoftInputMode="adjustResize"
                    >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
        </application>
    </manifest>
    
    0 讨论(0)
  • 2020-12-16 01:31

    Hi I encountered this problem as well. The issue I had was I added adjustResize as shown below in my Manifest

    and it still wouldn't scroll. But in my xml file in the beginning of my ScrollView

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/top"
        android:scrollbars="none" >
    

    I deleted android:scrollbars="none" and that solved my problem. Just for anyone whose adjustment on the manifest did not work.

    0 讨论(0)
提交回复
热议问题