28

我有一个布局有一些视图,其中一个是EditText。布局很容易放在一个页面上,但是,当软键盘出现时,布局不会滚动。 这里是我的布局的概括:Android:ScrollView不能滚动键盘输出

<?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:background="@drawable/background" > 

    <ScrollView 
     android:id="@+id/ScrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <CheckBox/> 

      <TextView/> 

      <LinearLayout> 
       <EditText> 
        <requestFocus /> 
       </EditText> 
      </LinearLayout> 

      <TextView/> 

      <LinearLayout> 
       <Spinner/> 
      </LinearLayout> 

     </LinearLayout> 

    </ScrollView> 

    <Button 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout> 

而在我的表现我已经宣布的属性:

android:windowSoftInputMode="adjustResize|stateHidden" 

有谁知道为什么它不工作,如何确保它的工作?

在此先感谢!

+1

对于Android 5,请查看以下相关文章:[Android - 调整键盘为Android 5.0(棒棒糖)时滚动视图](http://stackoverflow.com/questions/27167176/android-adjust-scrollview-when- keyboard-is-up-for-android-5-0-lollipop) – 2015-11-27 07:49:29

回答

28

好的,显然ScrollView的android:layout_height一定不能设为wrap_content。我将它设置为match_parent并将android:layout_above设置为页面底部的按钮。

不要问我为什么,但是这个问题解决了。

+0

'layout_above'什么? – 2015-07-09 15:51:28

+5

'layout_above'无论您想要在屏幕上修改哪个视图 – Xander 2015-07-10 20:56:47

+1

您是一名救生员:) – letronje 2016-10-07 15:48:52

35

我有同样的问题,我查了一下我的活动清单,为什么它不工作的原因是因为我没有使用这个属性:

android:windowSoftInputMode="adjustResize" 

现在,它的伟大工程,无需要做额外的锚定。

9

android:windowSoftInputMode="stateHidden|adjustResize"添加到您在AndroidManifest.xml文件中的标记中。在显示软键盘后,这将导致屏幕被调整到左侧空间。所以,你将可以轻松滚动。

+1

太棒了,它对我很好(y) – Rifinio 2015-04-28 15:22:49

0

我的问题是一个Horizo​​ntalScrollView。在我而言,我不得不Horizo​​ntalScrollView设置为:

android:layout_width="match_parent" 
android:layout_height="match_parent" 

,并删除:

android:layout_above="@+id/closeButton" 
android:layout_below="@+id/logo" 

在AndroidManifest.xml活动设置为:

android:windowSoftInputMode="" 

我希望这可以帮助任何人通过这个奇怪的错误。

0

尝试将ScrollView设置为您的父级布局。它对我来说就像魅力!

5

在我的情况下,没有任何上述工作。

我在我的主题中有item name="android:windowTranslucentStatus">true</item>。它通过在父布局中设置android:fitsSystemWindows="true"得到修复,我的滚动视图在哪里。