我正在使用Android应用。这个程序有教程屏幕。在本教程中,用户必须向右和向左滑动才能完成教程。当它启动应用程序时,它会显示名为SwipeLeftFragment的第一个片段。当用户向左滑动时,它会显示名为SwipeRightFragment的第二个片段。当用户向右滑动时,它会显示名为CompletedTutorialFragment的第三个片段。 目前它工作正常但动画不起作用。 以下是我的代码:
public class TutorialActivity extends FragmentActivity {
@Override
protected void onStart() {
super.onStart();
final swipeLeftFragment swipeLeftFragment = new SwipeLeftFragment();
addFragmentToBottom(swipeLeftFragment);
swipeLeftFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
@Override
public void onSwipeRight() {
}
@Override
public void onSwipeLeft() {
TranslateAnimation animation = new TranslateAnimation(0, -swipeLeftFragment.getView().getWidth(), 0, 0);
animation.setDuration(5000);
swipeLeftFragment.getView().startAnimation(animation);
swipeLeftFragment.getView().setVisibility(View.GONE);
final SwipeRightFragment swipeRightFragment = new SwipeRightFragment();
addFragmentToBottom(swipeRightFragment);
swipeRightFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
@Override
public void onSwipeRight() {
TranslateAnimation animation = new TranslateAnimation(0, +swipeRightFragment.getView().getWidth(), 0, 0);
animation.setDuration(5000);
swipeRightFragment.getView().startAnimation(animation);
swipeRightFragment.getView().setVisibility(View.GONE);
final CompletedTutorialFragment completedTutorialFragment = new CompletedTutorialFragment();
addFragmentToBottom(completedTutorialFragment);
startSignupActivity();
}
@Override
public void onSwipeLeft() {
}
});
}
});
}
private void startSignupActivity() {
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(TutorialActivity.this, SignUpActivity.class));
}
}, 2000L);
}
}
有人能告诉我我的代码有什么问题吗?
这是 OnTouchListener我正在使用