我想从右到左使用幻灯片动画效果使视图可见,反之亦然。我已经成功地隐藏了一个从左到右滑动动画的视图,但无法实现另一个。以下是我正在使用的代码片段:
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();
}
}
Run Code Online (Sandbox Code Playgroud)