2011-10-27 114 views
1

這是我的應用程序,當軟鍵盤被隱藏時 enter image description here 但是當顯示鍵盤時,頂部的edittext框消失了(它被向上推)。 enter image description here 它看起來像這樣。顯示鍵盤時的佈局問題

我的問題是如何在顯示鍵盤時保持編輯框可見?我想只有在編輯框中之間的空間被縮小...但兩個框是可見的

我的佈局到目前爲止是這樣

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" android:layout_width="fill_parent" 
    android:id="@+id/relativeLayout1"> 
    <EditText android:id="@+id/editText1" android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" android:layout_width="fill_parent"> 
     <requestFocus></requestFocus> 
    </EditText> 
    <EditText android:id="@+id/editText2" android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" android:layout_width="fill_parent"></EditText> 
    <ImageView android:id="@+id/imageView1" 
     android:layout_height="wrap_content" android:layout_below="@id/editText1" 
     android:layout_above="@id/editText2" android:background="@drawable/icon" 
     android:layout_width="fill_parent"></ImageView> 
</RelativeLayout> 

回答

5

轉到您的Android清單並更改「窗口軟調節「(adjustPan),它將整個視圖移動到adjustResize,這將調整視圖的大小。

+1

在我的清單中,我把android:windowSoftInputMode =「stateVisible | adjustResize」,它的工作原理,但你可以給我一個簡短的解釋是什麼,這是可以改變代碼? – Lukap

+0

Android會嘗試爲您處理視圖,以確保您輸入的字段不會被鍵盤隱藏。有很多方法可以做到這一點。平移只是移動整個視圖,直到您可以看到該字段。調整大小調整整個視圖以佔用未被鍵盤隱藏的空間,這正是您想要的。我知道無法在代碼中設置它,但可能有一個地方。儘管在xml中設置它是標準的。 –