2014-07-02 81 views
2

已經搜索了很多,但無法找到一個令人滿意的解決方案。下面的截圖描述了我正面臨的問題。edittext隱藏在標題欄當軟鍵盤可見

enter image description here

EDITTEXT背後隱藏標題欄時,軟鍵盤是可見的。我已經把

android:gravity="center_vertical" 

屬性在主佈局。如果我刪除此屬性,佈局工作fine.But設計要求所需要的形式是在center.I使用everything.Tried滾動視圖並投入清單

android:windowSoftInputMode="stateVisible|adjustResize" 

這也嘗試過「adjustPan」,並試圖它確實有用。但是在這種情況下,整個表單不會被推高。編輯文本'MobileNo'並且按鈕保持隱藏在軟鍵盤後面。

佈局XML代碼:

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


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="324dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:background="#39CCCCCC" 
     android:orientation="vertical" 
     android:isScrollContainer="true" 
     android:padding="5dp" 
     > 

    <EditText android:id="@+id/edit_name" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:hint="@string/register_name" 
     android:textColor="@color/black" 
     android:textSize="20sp" 
android:background="@drawable/rounded_edittext_bg" 
     android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
     android:layout_marginTop="20dp" 
     android:padding="5dp" 
     android:inputType="textPersonName"/> 

<EditText android:id="@+id/edit_email" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:hint="@string/register_emailid" 
     android:textColor="@color/black" 
     android:textSize="20sp" 
android:background="@drawable/rounded_edittext_bg" 
     android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:padding="5dp" 
     android:inputType="textEmailAddress" /> 

<EditText android:id="@+id/edit_password" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:hint="@string/register_pass_hint" 
     android:textColor="@color/black" 
     android:textSize="20sp" 
android:background="@drawable/rounded_edittext_bg" 
     android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:padding="5dp" 
     android:inputType="textPassword" /> 

<EditText android:id="@+id/edit_confpassword" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:hint="@string/register_confpass" 
     android:textColor="@color/black" 
     android:textSize="20sp" 
android:background="@drawable/rounded_edittext_bg" 
     android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:padding="5dp" 
     android:inputType="textPassword" /> 

<EditText android:id="@+id/edit_mobile" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:hint="@string/register_mobile" 
     android:textColor="@color/black" 
     android:textSize="20sp" 
android:background="@drawable/rounded_edittext_bg" 
     android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:padding="5dp" 
     android:maxLength="11" 
     android:inputType="phone"/> 



<Button android:id="@+id/signup_btn" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/edittext_dimen" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_gravity="center_horizontal" 
     android:text="@string/register_signup" 
     android:textSize="20sp" 
     android:background="#3F799F" 
     android:textColor="@color/white"/> 
</LinearLayout> 
</LinearLayout> 

對此有任何解決方案?任何可以幫助我實現目標的解決方法?請回復您的意見和建議。

如果您無法理解我的疑問,請隨時提問。 預先感謝您。

+0

它,因爲你必須使用相對佈局。我可能是錯的,但是你已經給出了按鈕以實現底部真實,以及按鈕上方的其他關係。發佈清除IDEA的XML文件。 –

+0

當鍵盤出現時,您唯一能掌握的就是軟輸入模式,唯一的選擇是平移和調整大小。您可能會對佈局進行更改以改善內容,但鍵盤沒有設置可以解決問題。 –

+0

http://android-developers.blogspot.in/2009/04/updating-applications-for-on-screen.html –

回答

3

我解釋一下你的錯誤。當鍵盤打開「線性佈局」需要屏幕上有足夠的空間以使其上升並且不可見時,您已將襯裏佈局設置爲324dp .so。您的第一個編輯文本。

改爲使用相對佈局。

等一下我給你修改的XML。直到時間檢查你的XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center_vertical" 
android:orientation="vertical" 
android:padding="5dp" > 

<LinearLayout 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:background="#39CCCCCC" 
    android:isScrollContainer="true" 
    android:orientation="vertical" 
    android:padding="5dp" > 

    <EditText 
     android:id="@+id/edit_name" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="20dp" 
     android:hint="Name" 
     android:inputType="textPersonName" 
     android:padding="5dp" 
     android:textColor="#000" 
     android:textSize="20sp" /> 

    <EditText 
     android:id="@+id/edit_email" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:hint="Email" 
     android:inputType="textEmailAddress" 
     android:padding="5dp" 
     android:textColor="#000" 
     android:textSize="20sp" /> 

    <EditText 
     android:id="@+id/edit_password" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:hint="password" 
     android:inputType="textPassword" 
     android:padding="5dp" 
     android:textColor="#000" 
     android:textSize="20sp" /> 

    <EditText 
     android:id="@+id/edit_confpassword" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:hint="Confirm password" 
     android:inputType="textPassword" 
     android:padding="5dp" 
     android:textColor="#000" 
     android:textSize="20sp" /> 

    <EditText 
     android:id="@+id/edit_mobile" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:hint="register" 
     android:inputType="phone" 
     android:maxLength="11" 
     android:padding="5dp" 
     android:textColor="#000" 
     android:textSize="20sp" /> 

    <Button 
     android:id="@+id/signup_btn" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:background="#3F799F" 
     android:text="signup" 
     android:textColor="#fff" 
     android:textSize="20sp" /> 
</LinearLayout> 

</RelativeLayout> 

活動代碼清單中寫這個android:windowSoftInputMode="adjustResize|adjustPan"

我改變你的漁政船,大小,顏色也字符串resourch

+0

是的,如果我設置linearlayout的高度來包裝內容.. edittext不隱藏在標題欄後面,但然後手機號碼和註冊按鈕隱藏在softkeyboard後面,它甚至不會在鍵盤可見時滾動。我希望用戶應該能夠滾動,直到註冊按鈕,即使鍵盤激活 –

+0

嘿thanx ..問題已解決..我改變了linearlayout的高度來包裝內容,如你所說,並把它放在scrollview中,並提到這在manisfest android:windowSoftInputMode =「stateVisible | adjustResize」 ..即使主佈局是LinearLayout.Thanx,也是如此。:) –

+0

您的Wellcome狐狸。 –

1

在清單中添加adjustPanactivity標籤

android:windowSoftInputMode="adjustResize|adjustPan"