gpt4 book ai didi

Android setError 不跟随下滑动画

转载 作者:太空狗 更新时间:2023-10-29 15:02:32 25 4
gpt4 key购买 nike

我的 android 应用程序中有以下页面(我无法截取该页面的屏幕截图,所以我只是画了它):我有 edittexts 并且我使用 edittext 的 showError 属性。

enter image description here

然后,在程序的某个时刻,整个页面动画并向下滑动。问题是,当edittexts往下滑的时候,错误信息并没有滑动,而是保持原位,变成了这样:

enter image description here

这是我的编辑文本布局文件:

<RelativeLayout 
android:layout_marginTop="10dp"
android:id="@+id/loginFieldsPanel"
android:layout_below="@+id/loginWarningPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/login_edit_fields_bg">
<RelativeLayout
android:id="@+id/userNamePanel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/userNameWithBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_eposta_image_bg"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_username_left_image"/>
</RelativeLayout>

<com.example.CustomEditText
android:paddingRight="5dp"
android:id="@+id/editUserName"
android:layout_toRightOf="@+id/userNameWithBg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_centerVertical="true"
android:textSize="16sp"
custom:customFontType="regular"
android:hint="@string/login_identity_hint"
android:background="@null"/>
</RelativeLayout>
<ImageView
android:id="@+id/login_fields_line"
android:layout_below="@+id/userNamePanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/login_fileds_line"/>
<RelativeLayout
android:layout_below="@+id/login_fields_line"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/passwordWithBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_password_image_bg"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_password_left_image"/>
</RelativeLayou
<com.example.CustomEditText
android:layout_margin="5dp"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/passwordWithBg"
android:id="@+id/editPassword"
android:background="@null"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
custom:customFontType="regular"
android:hint="@string/login_password_hint"/>
</RelativeLayout>

</RelativeLayout>

下面是我如何执行动画:

ObjectAnimator.ofFloat(basePanel, "translationY", start, finish).setDuration(duration).start();

其中 basePanel 是我的布局文件的根布局。

那么,谁能帮我解决这个问题?

谢谢

最佳答案

  1. 最简单的方法是为外部布局添加此属性:android:animateLayoutChanges="true"
  2. 这里有两种方法可以让 View 开始向上滑动和向下滑动。

    public TranslateAnimation getShow()
    {
    TranslateAnimation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    mShowAction.setDuration(500);
    return mShowAction;
    }

    public TranslateAnimation getHide()
    {
    TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
    0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
    -1.0f);
    mHiddenAction.setDuration(500);
    return mHiddenAction;
    }

    使用方法:

    view.startAnimation(getShow());

关于Android setError 不跟随下滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25154267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com