2016-05-10 107 views
0

我有一些編輯文本在佈局文件中,軟鍵盤覆蓋了一些編輯文本。我希望整個編輯文本應該向上滾動,如果用戶點擊第一個編輯文本,以便所有的字段一次可見。我嘗試在XML文件中添加ScroolView,isScrollContainer,orientation:vertical,requestFocus,android:imeOptions =「flagNoFullscreen」,並在Manifest中添加了android:windowSoftInputMode =「adjustPan | adjustResize」。但沒有得到預期的結果。 這裏是我的xml文件軟鍵盤覆蓋EditText字段android

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:background="@drawable/register_back" 
tools:context="com.example.RegisterActivity"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/registerFieldsRL" 
    android:layout_marginTop="40dp"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/header" 
     android:text="Register" 
     android:textAllCaps="true" 
     android:textColor="#646b99" 
     android:textSize="18dp" 
     android:gravity="center" 
     android:layout_centerHorizontal="true" /> 
    <EditText 
     android:id="@+id/nameET" 
     android:hint="Enter Your Name" 
     android:layout_below="@+id/header" 
     style="@style/editTextStyle" 
     android:layout_marginTop="10dp" 
     android:singleLine="true"/> 
    <EditText 
     android:id="@+id/emailET" 
     android:hint="Enter Your Email Id" 
     android:layout_below="@+id/nameET" 
     style="@style/editTextStyle" 
     android:layout_marginTop="5dp" 
     android:singleLine="true"/> 

    <EditText 
     android:id="@+id/mobileET" 
     android:hint="Enter Your Mobile Number" 
     android:layout_below="@+id/emailET" 
     style="@style/editTextStyle" 
     android:layout_marginTop="5dp" 
     android:singleLine="true"/> 
    <EditText 
     android:id="@+id/passwordET" 
     android:hint="Enter Password" 
     android:layout_below="@+id/mobileET" 
     style="@style/editTextStyle" 
     android:layout_marginTop="5dp" 
     android:singleLine="true"/> 
    <EditText 
     android:id="@+id/confrm_passwordET" 
     android:hint="Re-enter Password" 
     android:layout_below="@+id/passwordET" 
     style="@style/editTextStyle" 
     android:layout_marginTop="5dp" 
     android:singleLine="true"/> 
    <Button 
     android:layout_width="200dp" 
     android:layout_height="40dp" 
     android:id="@+id/logon_button" 
     android:text="Logon" 
     android:gravity="center" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/confrm_passwordET" 
     android:layout_marginTop="7dp" 
     android:background="#db96a3" 
     android:textColor="#e8d3c1"/> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/social_loginsRL" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="30dp"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/social_login_header" 
     android:text="- OR LOGIN WITH -" 
     android:layout_centerHorizontal="true" 
     android:textColor="#646b99" 
     android:textSize="18dp"/> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_below="@+id/social_login_header" 
     android:layout_marginTop="10dp"> 
     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/facebook_button" 
      android:background="@drawable/fbbutton" 
      android:layout_toLeftOf="@+id/social_login_split_view"/> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/social_login_split_view"></View> 
     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/gmail_button" 
      android:background="@drawable/gmailbutton" 
      android:layout_toRightOf="@+id/social_login_split_view" /> 
    </RelativeLayout> 

</RelativeLayout> 

這裏是我的風格的代碼

<style name="editTextStyle"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:background">@drawable/edittext_background</item> 
    <item name="android:gravity">center_horizontal</item> 
    <item name="android:backgroundTint">#e8d3c1</item> 
    <item name="android:textColor">#646b99</item> 
</style> 

,這是我的Drawable文件

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/patient_details_et_background"/> 
    <item> 
     <shape> 
     <stroke 
      android:width="1dp" 
      android:color="#d4c6c1" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
     </shape> 
    </item> 
    </selector> 
+0

如果您已經使用過「滾動視圖」,那麼它應該是可行的。使用它時有什麼問題? –

+0

googlebutton和facebook按鈕覆蓋了edittext的其餘部分,只有兩個edittext字段可見。 – Tara

+0

那麼你所有的5個'Edit Texts'都不可滾動? –

回答

0

塔拉,從我的理解你的問題,(也許我錯了),你希望你的佈局中的所有編輯文本向上滾動,並在你點擊任何EditText的時候都處於焦點?

假設您的佈局中有10個EditText,並且用戶單擊第一個EditText,如果所有EditText都向上滾動,則用戶單擊的項目也會從焦點移開。這對用戶來說並不好,因爲他們無法在他們點擊的實際字段上進行編輯。

至於這個問題,我會說把所有的EditText放在一個ScrollView中,並在scroll view上放一個屬性android:fillViewport =「true」。這不會解決問題,但您將能夠在預覽窗格中的滾動視圖中看到完整長度和項目。

一旦彈出窗口,soft關鍵字將覆蓋屏幕的某個區域,但您應該確保用戶可以在佈局中的每個視圖上滾動。

+0

我已經添加了滾動視圖,並且還能夠滾動。我在我的佈局中有5個編輯文本,要求用戶應該能夠看到所有5個編輯文本,因爲頂部有一些空格,軟鍵盤覆蓋了最後一個編輯文本的一半。這是我的問題。 – Tara