TextInputLayout中的EditText滞后 [英] EditText in TextInputLayout lagging
问题描述
我有两个使用 TextInputLayout
的视图。第一个是只有两个输入字段的登录视图,第二个是有许多输入字段的注册视图。我正在使用带有自定义主题的 TextInputLayout
和 EditText
/ AppCompatEditText
问题是,当我在注册屏幕中单击我的 EditText
时,我在屏幕上出现了滞后/尖峰现象。默认的 TextInputLayout
动画。我的 LoginScreen
并没有滞后,但是我使用的代码是完全相同的,所以我想问题出在输入数量上。有任何想法或想法吗?
这是我的注册代码:
I have two views using TextInputLayout
. The first one is a login view which has only 2 input fields and the second one is a register view which has many input fields. I am using TextInputLayout
and EditText
/AppCompatEditText
with custom themes for my inputs.
The problem is, when i click on my EditText
's in my Register screen i get a kind of lag/spikes on the default TextInputLayout
animation. I don't get the lag in my LoginScreen
but the code I'm using is quite the same, so i suppose the problem is in the number of inputs. Any idea or thoughts?
Here is my register code:
<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" />
推荐答案
我认为出现延迟的原因是TextInputLayout的提示动画和对活动主窗口的调整是同时发生的(因为显示了软键盘)。
I believe that the reason for the lag is that the hint animation of TextInputLayout and the adjustment made to the activity's main window happening at the same time (because of showing soft keyboard).
在我的例子中,使用清单文件中活动标签内的 android:windowSoftInputMode = adjustNothing
可以完成此任务,因为它使键盘显示在内容上而没有任何内容对活动的主窗口进行了调整,但是由您决定键盘是否可以覆盖TextInputLayout。
In my case using android:windowSoftInputMode="adjustNothing"
inside the activity tag in Manifest does the job, because it makes keyboard appear over the content without any adjustment made to the activity's main window, however it is up to you to decide if keyboard can overlay your TextInputLayout.
作为最后一个选项,我们可以设置 app:hintAnimationEnabled = false
到TextInputLayout。
As the last option we can set app:hintAnimationEnabled="false"
to the TextInputLayout.
这篇关于TextInputLayout中的EditText滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!