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"得到修復,我的滾動視圖在哪裏。