TextInputLayout中的EditText滞后

时间:2016-01-25 12:38:43

标签: animation android-edittext android-textinputlayout

我使用TextInputLayout有两个观点。第一个是登录视图,它只有2个输入字段,第二个是具有许多输入字段的寄存器视图。我正在使用TextInputLayoutEditText / AppCompatEditText为我的输入添加自定义主题 问题是,当我点击我的注册屏幕中的EditText时,我会在默认的TextInputLayout动画上出现一种滞后/尖峰。我没有在LoginScreen中得到延迟,但我使用的代码完全相同,所以我想问题在于输入的数量。有什么想法或想法吗? 这是我的注册码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    app:title="Register as shipper"
    app:titleTextColor="@color/white" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="@dimen/space">

        <View
            android:layout_width="0px"
            android:layout_height="0px"
            android:focusable="true"
            android:focusableInTouchMode="true" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/fullNameEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_full_name"
                android:inputType="text"
                android:nextFocusLeft="@id/fullNameEdit"
                android:nextFocusUp="@id/fullNameEdit"
                android:theme="@style/EditText" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/companyNameEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_company_name"
                android:theme="@style/EditText" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/phoneNumberEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_phone_number"
                android:theme="@style/EditText"
                android:inputType="phone" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/emailEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_email"
                android:theme="@style/EditText"
                android:inputType="textEmailAddress" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/passwordEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_password"
                android:theme="@style/EditText"
                android:inputType="textPassword" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/hintTextOnLightBackgrounds"
            app:hintTextAppearance="@style/TextLabel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/addressEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:hint="@string/shipper_register_address"
                android:theme="@style/EditText"
                android:inputType="text" />

        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatSpinner
            android:id="@+id/typeSpinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp" />

        <Button
            android:id="@+id/registerBtn"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="@dimen/space"
            android:text="@string/shipper_register_register"
            android:theme="@style/ButtonPrimary" />

    </LinearLayout>
</ScrollView>

和登录:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/space">

<ImageView
    android:layout_width="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:src="@drawable/logo_color"
    android:layout_height="wrap_content" />

<View
    android:layout_width="0px"
    android:layout_height="0px"
    android:focusable="true"
    android:focusableInTouchMode="true" />

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="@color/hintTextOnLightBackgrounds"
    app:hintTextAppearance="@style/TextLabel">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/emailEdit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/login_email"
        android:inputType="textEmailAddress"
        android:theme="@style/EditText" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="@color/hintTextOnLightBackgrounds"
    app:hintTextAppearance="@style/TextLabel">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/passwordEdit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:hint="@string/login_password"
        android:inputType="textPassword"
        android:theme="@style/EditText" />
</android.support.design.widget.TextInputLayout>

<Button
    android:id="@+id/loginBtn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/login_login"
    android:theme="@style/ButtonPrimary" />

<Button
    android:id="@+id/shipperRegisterBtn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/login_register_as_shipper"
    android:theme="@style/ButtonPrimary" />

<Button
    android:id="@+id/carrierRegisterBtn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/login_register_as_carrier"
    android:theme="@style/ButtonPrimary" />

1 个答案:

答案 0 :(得分:1)

我认为出现延迟的原因是TextInputLayout的提示动画和对活动主窗口的调整是同时发生的(因为显示了软键盘)。

在我的情况下,使用清单文件中活动标签内的padding-left可以完成此工作,因为它使键盘显示在内容上方,而无需对活动的主窗口进行任何调整,但是您可以自行决定是否使用键盘可以覆盖您的TextInputLayout。

作为最后一个选项,我们可以将android:windowSoftInputMode="adjustNothing"设置为TextInputLayout。