我在我的android应用程序中有以下页面(我不能截取页面的截图,所以我只需绘制它):我有edittext,并且使用edittext的showerror属性。
然后,在程序的某个点上,整个页面都会动画化并向下滑动。问题是,当EditText向下滑动时,错误消息不会滑动,它会保持其位置,并变成这样:
这是我的编辑文本布局文件:
<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是布局文件的根布局。
有人能帮我修一下吗?
谢谢
最佳答案
简单的方法是外部布局添加这个属性:android:animateLayoutChanges="true"
。
这里有两种方法让视图开始向上滑动和向下滑动。
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 - Android setError不跟随下滑动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25154267/