2011-08-23 36 views
2

我想軟鍵盤,所以用戶可以輸入他的信息在我的android應用程序上創建一個新的帳戶。問題是我的一些TextEdit總是在屏幕外流動,用戶看不到他實際輸入的內容。屏幕看起來是這樣的:Android:軟鍵盤移動TextEdit不在屏幕

screenshot

該屏幕採用以下XML代碼內置:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:orientation="vertical" 
android:layout_height="fill_parent">  

    <com.markupartist.android.widget.ActionBar 
     android:id="@+id/actionbar" 
     style="@style/ActionBar"/>  

    <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1.0"> 

    <LinearLayout 
     android:layout_gravity="bottom" 
     android:paddingTop="15dip" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <EditText android:id="@+id/txtPhoneNumber" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:nextFocusUp="@+id/LoginButton" 
      android:nextFocusDown="@+id/txtPassword" 
      android:hint="Phone Number" 
      android:inputType="number" 
      android:singleLine="true" /> 

     <EditText android:id="@+id/txtPassword" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:singleLine="true" 
      android:nextFocusDown="@+id/txtName"/> 

     <EditText android:id="@+id/txtName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Name" 
      android:singleLine="true" 
      android:nextFocusDown="@+id/txtPin" /> 

     <EditText android:id="@+id/txtPin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Pin" 
      android:inputType="number" 
      android:singleLine="true" />    

    </LinearLayout> 

    </ScrollView> 

    <LinearLayout android:id="@+id/buttonsLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" >  

    <Button android:id="@+id/btnLogin" 
     android:layout_width="fill_parent"   
     android:layout_height="wrap_content" 
     android:layout_weight="1.0" 
     android:text="@string/btnLogin"      
     android:onClick="onRegisterClick" />        

</LinearLayout> 

在我的AndroidManifest.xml我定義我的活動是這樣的:

<activity android:name=".activity.NewAccountActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:windowSoftInputMode="stateHidden|adjustResize" /> 

我試過我的不同組合的佈局和windowSoftInputMode,但我永遠不會得到被修改的TextEdit在屏幕上可見。我在這裏錯過了什麼嗎?

感謝 牛逼

回答

1

您可以使用adjustPan保持屏幕上的可視區域內的場:

android:windowSoftInputMode="stateHidden|adjustPan" 

更新

儘量不要使用ScrollViewView之外。我已將您的佈局更改爲擁有一個頂級ScrollView和內部LinearLayout。所有其他元素都位於LinearLayout內。這是因爲在調整軟鍵盤的屏幕時,Android不知道如何正確滾動ScrollView

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    android:layout_weight="1.0" >  

    <LinearLayout 
     android:layout_gravity="bottom" 
     android:paddingTop="15dip" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <EditText android:id="@+id/txtPhoneNumber" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:nextFocusUp="@+id/LoginButton" 
      android:nextFocusDown="@+id/txtPassword" 
      android:hint="Phone Number" 
      android:inputType="number" 
      android:singleLine="true" /> 

     <EditText android:id="@+id/txtPassword" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:singleLine="true" 
      android:nextFocusDown="@+id/txtName"/> 

     <EditText android:id="@+id/txtName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Name" 
      android:singleLine="true" 
      android:nextFocusDown="@+id/txtPin" /> 

     <EditText android:id="@+id/txtPin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:hint="Pin" 
      android:inputType="number" 
      android:singleLine="true" /> 

     <LinearLayout android:id="@+id/buttonsLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_marginTop="20dip" 
      android:layout_marginLeft="15dip" 
      android:layout_marginRight="15dip" 
      android:orientation="vertical">  

      <View 
      android:layout_width="fill_parent"   
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

       <Button android:id="@+id/btnLogin" 
        android:layout_width="fill_parent"   
        android:layout_height="wrap_content" 
        android:text="login"      
        android:onClick="onRegisterClick" />        

     </LinearLayout> 

    </LinearLayout> 

</ScrollView> 
+0

多數民衆贊成他們的方式屏幕看起來當我設置adjustPan。當焦點集中在最後一個退出文本上時,鍵盤已經結束了。 http://imageshack.us/photo/my-images/705/deviceq.png/ – Thiago

+0

我已經更新了答案。 – inazaruk

+0

這個變化伎倆!非常感謝@inazaruk – Thiago

2

你滾動視圖設置爲FILL_PARENT,那並不這項事業的管制垂直剪裁任何答覆?如果您想要垂直拉伸,請將layout_height設置爲0dip。

您也可能想嘗試更換活動的windowSoftInputModeadjustPan

+0

http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft – Kurru

+0

我剛纔想這個。同樣的事情,如果我將焦點設置爲電話號碼editext,它會熄滅,我不能看到我正在輸入的內容。謝謝 – Thiago

4

更換adjustResize在AndroidManifest.xml後您的活動標籤加入這一行。

android:windowSoftInputMode="adjustPan" 

這樣

<activity android:name=".activity.NewAccountActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"/> 

希望工程。

+0

這會導致軟鍵盤顯示在字段上,並且它們不會滾動到鍵盤。 – Thiago