Using Animation to swipe views

后端 未结 2 1372
轻奢々
轻奢々 2021-01-15 02:12

I have a FrameLayout that recognize swipe gestures (up and down).

For example: if a swipe up are performed, I should animate the current view (that is MATCH_PARENT x

2条回答
  •  无人共我
    2021-01-15 03:08

    I solved this way:

    private void swipeUp() {
        current.currentPage++;
    
        final View hidingView = currentView;
        TranslateAnimation hide = new TranslateAnimation(0, 0, 0, -getHeight());
        hide.setAnimationListener(new AnimationListenerAdapter() {
            @Override
            public void onAnimationEnd(Animation animation) {
                hidingView.setVisibility(View.GONE);
            }
        });
        hide.setDuration(1000);
        hidingView.startAnimation(hide);
    
        TranslateAnimation show = new TranslateAnimation(0, 0, getHeight(), 0);
        show.setFillAfter(true);
        show.setDuration(1000);
    
        View nextView = getView();
        addView(nextView, createLP());
    
        nextView.startAnimation(show);
        currentView = nextView;
    }
    

提交回复
热议问题