2014-03-03 82 views
5

我似乎無法使android:windowSoftInputMode =「stateVisible | adjustResize」選項起作用。 當軟鍵盤顯示時,滾動視圖不會自動滾動到底部。爲什麼android:windowSoftInputMode =「stateVisible | adjustResize」在顯示軟鍵盤時調整屏幕?

編輯:我嘗試使用adjustPan來代替(stateVisible | adjustPan),但會發生什麼情況是滾動視圖被禁用。

解決方案:最後,我發現一個可行的建議。我創建了一個OnGlobalLayoutListener()並將其添加到我的滾動視圖中。我檢查了我的活動(這是我的滾動視圖)的根視圖的高度是否改變。如果是,我假設顯示軟鍵盤。

點擊here獲取更多信息。

這裏是我的源代碼:

AndroidManifest.xml中

<application 
     ... 
     android:theme="@android:style/Theme.NoTitleBar" > 
     <activity 
      ... 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="stateVisible|adjustResize" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     ... 
</application> 

登錄屏幕與鍵盤 - 滾動視圖不滾動 enter image description here

期望的結果 enter image description here

+0

使用Android:windowSoftInputMode = 「adjustPan | adjustResize」 – Piyush

+0

到adjustPan類似| stateVisible,這將禁用滾動視圖。 –

回答

4

解決方案:最後,我發現一個可行的建議。我創建了一個OnGlobalLayoutListener()並將其添加到我的滾動視圖中。我檢查了我的活動(這是我的滾動視圖)的根視圖的高度是否改變。如果是,我假設顯示軟鍵盤。

點擊here獲取更多信息。

0

android:windowSoftInputMode="adjustPan|stateVisible" 
+1

對不起。我忘了提及我已經嘗試過了。如果使用adjustPan,滾動視圖將不再滾動。 –

1

你可以自己自動滾動到你的活動的底部,通過重寫onConfigurationChanged()回調你Activity

scrollView.post(new Runnable() {    
    @Override 
    public void run() { 
      scrollView.fullScroll(View.FOCUS_DOWN);    
    } 
}); 

這意味着你也必須告訴你的活動,你要回調

:當活動通過使用活動聲明 configChanges屬性,在 AndroidManifest文件更改其佈局被稱爲

我希望這可以幫助你。

+0

我加了onConfigurationChanged(),但沒有被調用。即使在我的AndroidManifest.xml中添加了configChanges參數之後。 –

+0

你怎麼知道它沒有被調用?你是否試圖在logcat中打印一條消息來看? – Flawyte

+0

嗨。是。我在該方法中添加了一個Log.i()調用。無論如何,我終於找到了一個可行的解決方案。我將編輯我的文章以包含它。謝謝! –

-2

我發現,如果我對我的滾動視圖設置佈局參數,那麼它是行不通的。只要刪除了佈局參數,它就按預期工作。我無法解釋爲什麼,只是讓別人知道對我有用。

0

在清單:

android:windowSoftInputMode="adjustPan|stateVisible" 

,滾動型的所有子佈局的佈局XML底部設置一個TextView的,如

<ScrollView 
    android:id="@+id/driverLoginScrollView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="false" 
    android:scrollbars="none"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="50dp" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:orientation="vertical"> 
     . 
     . 
     . 
     <TextView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:focusable="false" 
     android:textIsSelectable="false" /> 
     </LinearLayout> 
</ScrollView> 
相關問題