android-如何制作适当的移入/移出动画?
作者:互联网
在onViewCreate中,将视图设置在屏幕后面:
holderMenus.post(new Runnable() {
@Override public void run() {
if (holderMenus != null) {
if (DeviceType.INSTANCE.tablet) {
holderMenus.animate().translationY(-holderMenus.getHeight());
} else {
holderMenus.animate().translationY(holderMenus.getHeight());
}
}
}
});
然后,当我要将视图移入时:
holderMenus.animate().translationY(0).setDuration(300);
那很好视图滑入.接下来,我想将视图移出屏幕:
if (DeviceType.INSTANCE.tablet) {
holderMenus.animate().translationY(-holderMenus.getHeight()).setDuration(300);
} else {
holderMenus.animate().translationY(holderMenus.getHeight()).setDuration(300);
}
但是视图不会消失,而是消失了,就像我将属性设置为.setVisibility(View.GONE);一样.
我该如何使其滑动?
解决方法:
我制作了一个自定义操作按钮,该按钮可在屏幕下方滑动,并在滚动列表视图时在屏幕下方滑动.
皮:
TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 500);
anim.setDuration(300l);
anim.setFillAfter(true);
layout.startAnimation(anim); //layout is the layout with the button
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
layout.clearAnimation();
layout.setVisibility(View.GONE);
}
}, 300l);
显示:
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
try {
layout.setVisibility(View.VISIBLE);
TranslateAnimation anim = new TranslateAnimation(0, 0, 500, 0);
anim.setDuration(300l);
anim.setFillAfter(true);
layout.startAnimation(anim);
} catch (Exception e) {
e.printStackTrace();
}
}
}, 500l);
标签:android-animation,android 来源: https://codeday.me/bug/20191118/2025134.html