2016-05-10 106 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