当键盘打开时,在Android中滚动窗体不起作用

时间:2017-01-12 23:38:48

标签: android android-layout

我有一个注册表单,其中包含几个TextEdits和TextViews来显示错误。问题是当键盘打开时,用户无法向下滚动到底部元素,尽管为清单文件中的活动设置了此属性:

android:windowSoftInputMode="stateVisible|adjustPan"




 <?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <com.nvanbenschoten.motion.ParallaxImageView
        android:id="@+id/background_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/dark"
         />
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/trending_gradient_shape" />
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">
    <LinearLayout
        android:animateLayoutChanges="true"
        android:id="@+id/mainLayout"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            app:titleTextColor="@color/color_white"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@null"
            android:elevation="4dp"
            android:theme="@style/ToolbarThemeWhite"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>


        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/ivUserPhoto"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_gravity="center"
            android:src="@drawable/ic_user"
            android:layout_centerVertical="true"
            app:civ_border_color="@android:color/white"
            app:civ_border_width="4dp"/>

        <EditText
            android:textColorHint="@color/color_white"
            android:paddingLeft="15dp"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="First Name"
            android:textColor="@color/color_white"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/first_name"
            android:ems="10"
            android:singleLine="true"
            android:nextFocusDown="@+id/family_name"
            android:nextFocusForward="@+id/family_name"
                />
            <TextView
                android:visibility="gone"
                android:id="@+id/error_first_name"
                android:textColor="@color/color_red_700"
                android:text="error"
                android:layout_width="match_parent"
                android:layout_marginRight="@dimen/form_margin"
                android:layout_marginLeft="@dimen/form_margin"
                android:layout_height="20dp" />
        <LinearLayout
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>

        <EditText
            android:textColorHint="@color/color_white"
            android:paddingLeft="15dp"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Family Name"
            android:textColor="@color/color_white"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/family_name"
            android:ems="10"
            android:singleLine="true"
            android:nextFocusUp="@+id/first_name"
            android:nextFocusDown="@+id/email"
            android:nextFocusForward="@+id/email"
            />
        <TextView
            android:visibility="gone"
            android:id="@+id/error_family_name"
            android:textColor="@color/color_red_700"
            android:text="error"
            android:layout_width="match_parent"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_height="20dp" />
        <LinearLayout
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>







    <LinearLayout
        android:layout_marginRight="@dimen/form_margin"
        android:layout_marginLeft="@dimen/form_margin"
        android:layout_marginBottom="@dimen/margin_between_fields"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <com.foxtrapp.mysmallcommunity.ui.OnItemNotSelectedSpinner
            android:layout_gravity="center"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:id="@+id/gender"
            android:popupBackground="@null"
            android:entries="@array/gender"/>
        <TextView
            android:visibility="gone"
            android:id="@+id/error_gender"
            android:textColor="@color/color_red_700"
            android:text="error"
            android:layout_width="match_parent"
            android:layout_height="20dp" />
    </LinearLayout>


        <EditText
            android:textColorHint="@color/color_white"
            android:paddingLeft="15dp"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Email"
            android:nextFocusUp="@+id/family_name"
            android:textColor="@color/color_white"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/email"
            android:inputType="textEmailAddress"
            android:ems="10"
            android:singleLine="true"
            android:nextFocusDown="@+id/password"
            android:nextFocusForward="@+id/password"
            />
        <TextView
            android:visibility="gone"
            android:id="@+id/error_email"
            android:textColor="@color/color_red_700"
            android:text="error"
            android:layout_width="match_parent"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_height="20dp" />
        <LinearLayout
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>







        <EditText
            android:textColorHint="@color/color_white"
            android:paddingLeft="15dp"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Password"
            android:textColor="@color/color_white"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/password"
            android:inputType="textPassword"
            android:ems="10"
            android:singleLine="true"
            android:nextFocusUp="@+id/email"
            android:nextFocusDown="@+id/confirm_password"
            android:nextFocusForward="@+id/confirm_password"
            />
        <TextView
            android:visibility="gone"
            android:id="@+id/error_password"
            android:textColor="@color/color_red_700"
            android:text="error"
            android:layout_width="match_parent"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_height="20dp" />
        <LinearLayout
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>



        <EditText
            android:textColorHint="@color/color_white"
            android:paddingLeft="15dp"
            android:background="@drawable/normal_rounded_text_field"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Confirm Password"
            android:textColor="@color/color_white"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/confirm_password"
            android:inputType="textPassword"
            android:ems="10"
            android:singleLine="true"
            android:nextFocusUp="@+id/password"
            />
        <TextView
            android:visibility="gone"
            android:id="@+id/error_confirm_password"
            android:textColor="@color/color_red_700"
            android:text="error"
            android:layout_width="match_parent"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:layout_height="20dp" />
        <LinearLayout
            android:layout_marginBottom="@dimen/margin_between_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>


        <Button
            android:paddingLeft="15dp"
            android:layout_width="match_parent"
            android:layout_height="43dp"
            android:background="@drawable/button_get_st"
            android:layout_gravity="center"
            android:layout_marginRight="@dimen/form_margin"
            android:layout_marginLeft="@dimen/form_margin"
            android:text="Sign Up"
            android:textColor="#FFF"
            android:textSize="@dimen/form_field_text_size"
            android:id="@+id/confirm"
            android:visibility="visible" />

    </LinearLayout>
    </ScrollView>
</FrameLayout>

注意:当我添加textEdit而没有任何其他部分时,滚动效果很好,

2 个答案:

答案 0 :(得分:0)

You can try 

<RelativeLayout>
<ScrollView>
<RelativeLayout>
--------------------
Your EditText and other widget
-------------------
</RelativeLayout>
</ScrollView>
</RelativeLayout>

答案 1 :(得分:0)

我找到了答案;我认为在某种程度上,全屏模式和表单中的滚动之间存在矛盾。我不得不使用全屏代码删除以解决问题,即我从我的活动中删除了以下代码

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);