最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 軟鍵盤出現(xiàn)不適應的解決辦法總結

 更新時間:2017年03月20日 14:15:19   作者:劉望舒  
這篇文章主要介紹了Android 軟鍵盤出現(xiàn)不適應的解決辦法總結的相關資料,需要的朋友可以參考下

Android 軟鍵盤出現(xiàn)不適應的解決辦法總結

前言:

   很多寫登錄界面的開發(fā)者都會遇到一個問題:那就是在登錄界面時,當你點擊輸入框時,下邊的按鈕有時會被輸入框擋住,這個不利于用戶的體驗,所以很多人希望軟鍵盤彈出時,也能把按鈕擠上去。很多開發(fā)者想要監(jiān)聽鍵盤的狀態(tài),這無疑是一個很麻煩的做法。

       我們可以在AndroidManifest.xml的Activity設置屬性:Android:windowSoftInputMode = "adjustResize" ,軟鍵盤彈出時,要對主窗口布局重新進行布局,并調用onSizeChanged方法,切記一點當我們設置為“adjustResize”時,我們的界面不要設置為全屏模式,否則設置了這個屬性也不會有什么效果。而當我們設置android: windowSoftInputMode = "adjustPan"時,主窗口就不會調用onSizeChanged方法,界面的一部分就會被軟鍵盤覆蓋住,就不會被擠到軟鍵盤之上了。

我們通過一段代碼來測試一下,當我們設置了該屬性后,彈出輸入法時,系統(tǒng)做了什么:

重寫Layout布局:

public class ResizeLayout extends LinearLayout{ 
 private static int count = 0; 
  
 public ResizeLayout(Context context, AttributeSet attrs) { 
  super(context, attrs); 
 } 
  
 @Override 
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {  
  super.onSizeChanged(w, h, oldw, oldh); 
   
  Log.e("onSizeChanged " + count++, "=>onResize called! w="+w + ",h="+h+",oldw="+oldw+",oldh="+oldh); 
 } 
  
 @Override 
 protected void onLayout(boolean changed, int l, int t, int r, int b) { 
  super.onLayout(changed, l, t, r, b); 
  Log.e("onLayout " + count++, "=>OnLayout called! l=" + l + ", t=" + t + ",r=" + r + ",b="+b); 
 } 
  
 @Override 
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
  super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
   
  Log.e("onMeasure " + count++, "=>onMeasure called! widthMeasureSpec=" + widthMeasureSpec + ", heightMeasureSpec=" + heightMeasureSpec); 
 } 

我們的布局設置為:

<com.winuxxan.inputMethodTest.ResizeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/root_layout" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical" 
 > 
  
 <EditText 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
 /> 
  
 <LinearLayout 
   android:id="@+id/bottom_layout" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:orientation="vertical" 
   android:gravity="bottom">s 
  
 <TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="@string/hello" 
  android:background="#77777777" 
  /> 
 </LinearLayout> 
</com.winuxxan.inputMethodTest.ResizeLayout> 

AndroidManifest.xml的Activity設置屬性:android:windowSoftInputMode = "adjustResize"

    運行程序,點擊文本框,查看調試信息:

 E/onMeasure 6(7960): =>onMeasure called! widthMeasureSpec=1073742144, heightMeasureSpec = 1073742024
 E/onMeasure 7(7960): =>onMeasure called! widthMeasureSpec=1073742144, heightMeasureSpec = 1073742025
 E/onSizeChanged 8(7960): =>onSizeChanged called! w=320,h=201,oldw=320,oldh=377
 E/onLayout 9(7960): =>OnLayout called! l=0, t=0,r=320,b=201

    從調試結果我們可以看出,當我們點擊文本框后,根布局調用了onMeasure,onSizeChanged和onLayout。

  windowSoftInputMode的值如果設置為adjustPan,那么該Activity主窗口并不調整屏幕的大小以便留出軟鍵盤的空間。相反,當前窗口的內(nèi)容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內(nèi)容的部分。這個通常是不期望比調整大小,因為用戶可能關閉軟鍵盤以便獲得與被覆蓋內(nèi)容的交互操作。

    上面的例子中,我們將AndroidManifest.xml的屬性進行更改:android: windowSoftInputMode = "adjustPan"

    重新運行,并點擊文本框,查看調試信息:

 E/onMeasure 6(8378): =>onMeasure called! widthMeasureSpec=1073742144, heightMeasureSpec=1073742200
 E/onMeasure 7(8378): =>onMeasure called! widthMeasureSpec=1073742144, heightMeasureSpec=1073742201
 E/onLayout 8(8378): =>OnLayout called! l=0, t=0,r=320,b=377

    我們看到:系統(tǒng)也重新進行了measrue和layout,但是我們發(fā)現(xiàn),layout過程中onSizeChanged并沒有調用,這說明輸入法彈出前后并沒有改變原有布局的大小。

當然還有其他屬性可以設置:

"stateUnspecified"

軟鍵盤的狀態(tài)(是否它是隱藏或可見)沒有被指定。系統(tǒng)將選擇一個合適的狀態(tài)或依賴于主題的設置。

這個是為了軟件盤行為默認的設置。

"stateUnchanged"

軟鍵盤被保持無論它上次是什么狀態(tài),是否可見或隱藏,當主窗口出現(xiàn)在前面時。

"stateHidden"

當用戶選擇該Activity時,軟鍵盤被隱藏——也就是,當用戶確定導航到該Activity時,而不是返回到它由于離開另一個Activity。

"stateAlwaysHidden"

軟鍵盤總是被隱藏的,當該Activity主窗口獲取焦點時。

"stateVisible"

軟鍵盤是可見的,當那個是正常合適的時(當用戶導航到Activity主窗口時)。

"stateAlwaysVisible"

當用戶選擇這個Activity時,軟鍵盤是可見的——也就是,也就是,當用戶確定導航到該Activity時,而不是返回到它由于離開另一個Activity。

"adjustUnspecified"

它不被指定是否該Activity主窗口調整大小以便留出軟鍵盤的空間,或是否窗口上的內(nèi)容得到屏幕上當前的焦點是可見的。系統(tǒng)將自動選擇這些模式中一種主要依賴于是否窗口的內(nèi)容有任何布局視圖能夠滾動他們的內(nèi)容。如果有這樣的一個視圖,這個窗口將調整大小,這樣的假設可以使?jié)L動窗口的內(nèi)容在一個較小的區(qū)域中可見的。這個是主窗口默認的行為設置。

"adjustResize"

該Activity主窗口總是被調整屏幕的大小以便留出軟鍵盤的空間

"adjustPan"

該Activity主窗口并不調整屏幕的大小以便留出軟鍵盤的空間。相反,當前窗口的內(nèi)容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內(nèi)容的部分。這個通常是不期望比調整大小,因為用戶可能關閉軟鍵盤以便獲得與被覆蓋內(nèi)容的交互操作。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

最新評論

巍山| 西丰县| 黔西县| 民勤县| 庆城县| 普宁市| 建阳市| 株洲市| 景洪市| 会昌县| 大安市| 来凤县| 彰化县| 临夏县| 洛隆县| 西青区| 勃利县| 会泽县| 合山市| 公安县| 雅江县| 水城县| 铁岭县| 新安县| 虹口区| 英超| 三原县| 淄博市| 罗江县| 西充县| 西乌珠穆沁旗| 綦江县| 韩城市| 浑源县| 北安市| 万宁市| 宝清县| 定日县| 肇庆市| 宜兴市| 滨州市|