在res下建个anim文件夹,再建个translateout.xml文件
translateout
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%">
</translate>
在res下建个anim文件夹,再建个translatein.xml文件
translatein
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0">
</translate>
在使用的地方调用
private void showDateControl() {
if (isShowDateControl) {
isShowDateControl = false;
horizontalLv.clearAnimation();
Animation animation = AnimationUtils.loadAnimation(this, R.anim.translateout);
horizontalLv.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
horizontalLv.setVisibility(View.GONE);
horizontalLv.clearAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
} else {
isShowDateControl = true;
horizontalLv.setVisibility(View.VISIBLE);
horizontalLv.clearAnimation();
Animation animation = AnimationUtils.loadAnimation(this, R.anim.translatein);
horizontalLv.startAnimation(animation);
}
}