我想让 View 具有从右到左的幻灯片动画效果,反之亦然。我已经成功地能够隐藏具有从左到右幻灯片动画的 View ,但无法实现另一个 View 。 以下是我正在使用的代码 fragment :
private void showLayout(){
if(mContainerLayout.getVisibility() == View.VISIBLE){
mContainerLayout.animate()
.translationX(mContainerLayout.getWidth())
.setDuration(300)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mContainerLayout.setVisibility(View.GONE);
}
}).start();
}
else{
mContainerLayout.animate()
.translationX(0)
.setDuration(300)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mContainerLayout.setVisibility(View.VISIBLE);
}
}).start();
}
}
最佳答案
您可以添加淡入淡出动画:
private void showLayout(boolean show){
if (show){
mContainerLayout.animate()
.translationX(0)
.setDuration(300)
.alpha(1)
.start();
} else {
mContainerLayout.animate()
.translationX(mContainerLayout.getWidth())
.alpha(0)
.setDuration(300)
.start();
}
}
关于android - 如何在 Android 中滑动动画并使 View 从右向左可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505692/