2013-02-10 92 views
0

問題標題可能會引起誤解,但我認爲這是Android新手常見的問題:我有一個LinearLayout的活動,並且我有一個EditText在底部屏幕。當我點擊它時,鍵盤出現在EditText上,在鍵入時隱藏它。有沒有一種方法可以實現大多數用戶期望的功能,即活動會向下滾動直至EditText再次變爲可見?EditText被點擊時被鍵盤擋住了

+0

可能的重複http://stackoverflow.com/questions/6411267/softkeyboard-blocking-edittext – Pragnani 2013-02-10 17:13:50

回答

1

您可以使用ScrollView作爲頂視圖。並在那裏定義RelativeLayout

定義等作爲

<Scrollview.......> 
    <RelativeLayout .....> 
     //other view. 
    </RelativeLayout > 
</Scrollview> 
+0

@shridutt kothari我舉了一個例子,他如何將這個應用到他的問題中。 – 2013-02-10 17:32:08

1

您可以使用ScrollView來實現此目的。

+0

更新:是AVD *這*可怕嗎?我重新啓動了應用程序,現在它的行爲完全符合它的要求。 – whatyouhide 2013-02-10 17:13:04

+0

@whatyouhide AVDs一般是可怕的;) – Ahmad 2013-02-10 17:15:45

1

添加您LinearLayoutScrollviewEditText視圖獲取集中,manually scrollScrollView的內容。 就是這樣。

0

您是否曾嘗試將android:windowSoftInputMode="stateVisible|adjustResize"添加到清單中的活動中?

0

如果adjustResize仍然無法完全顯示您所期望的視圖,那麼您可以嘗試此操作。無論查看您的關注做出onTouchListener然後做到這一點:

setOnTouchListener(new OnTouchListener() { 



     Runnable shifter=new Runnable(){ 
      public void run(){ 
       try { 
        int[] loc = new int[2];     
        //get the location of someview which gets stored in loc array 
        findViewById(R.id.someview).getLocationInWindow(loc); 
        //shift so user can see someview 
        myscrollView.scrollTo(loc[0], loc[1]); 
       } 
       catch (Exception e) { 
        e.printStackTrace(); 
       } 
      }} 
     }; 

     Rect scrollBounds = new Rect(); 
     View divider=findViewById(R.id.someview); 
     myscollView.getHitRect(scrollBounds); 
     if (!divider.getLocalVisibleRect(scrollBounds)) { 
      // the divider view is NOT within the visible scroll window thus we need to scroll a bit. 
      myscollView.postDelayed(shifter, 500); 
     } 



    }); 

//實際上我們做一個可運行的是滾動到要在屏幕上看到一些視圖的新位置。只有當它不在滾動視圖範圍內時(它不在屏幕上),才能執行該可運行。這樣它將scrollview移動到引用的視圖(在我的情況下,'someview'是一個分隔線)。

0

最簡單的方法是將android:windowSoftInputMode="adjustPan"添加到清單中的目標活動。

相關問題