В настоящее время я реализую довольно простой экран входа в систему, используя пользовательскую реализацию TextInputLayout материала.Я использую пользовательский вид для отображения ошибок поля.Проблема здесь в том, что когда я устанавливаю вид из GONE в VISIBLE, он перемещает поля над и под ним.Я хочу, чтобы только представленные ниже виды двигались вниз, и оставлял их выше в той же позиции.
Я пытался использовать ViewPropertyAnimator , но это только оживляет появление и исчезновение ошибки.view.
errorView.visibility = View.VISIBLE
errorView.animate()
.alpha(1f)
.setListener(null)
.duration = 300
errorView.animate()
.alpha(0.0f)
.setDuration(300)
.setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
errorView.visibility = View.GONE
}
})
По сути, я хотел бы, чтобы вместо этого произошло следующее:
---------------------
| Email |
---------------------
<- Error to show here and move password field down
--------------------- |
| Password | v
---------------------
Result:
---------------------
| Email | <- Stay in same position
---------------------
----------------------
|Email must be valid | <- Error
----------------------
--------------------- |
| Password | v
---------------------
Ниже приведен пример компоновки XML, иллюстрирующей это.Обратите внимание, что это не соответствует моему макету, но все еще показывает ту же проблему.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 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:layout_centerInParent="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
<TextView
android:id="@+id/errorView"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="Email must be valid"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:visibility="gone"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Login"/>
</LinearLayout>
</RelativeLayout>