How to prevent ViewFlipper from looping

前端 未结 3 1097
梦毁少年i
梦毁少年i 2021-01-22 16:43

I am developing an application in which I am using a ViewFlipper with a custom OnTouch implementation. In the ViewFlipper, I have about 2

3条回答
  •  误落风尘
    2021-01-22 17:40

    Set an AnimationListener on the Viewflipper and then stop the animation when you reach the last slide.

        viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipperMain);              
        viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.slide_in_right));       
        viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left));   
    
        AnimationListener mAnimationListener = new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                //animation started event
            }
    
            public void onAnimationRepeat(Animation animation) {
            }
    
            public void onAnimationEnd(Animation animation) {
                //TODO animation stopped event
                if (viewFlipper.getDisplayedChild()==intLastChild){
                    viewFlipper.stopFlipping();
                }
            }
        };
    
       //Get a reference to one of the animations set on the ViewFlipper
       //In this example, I used the "In Animation"
       viewFlipper.getInAnimation().setAnimationListener(mAnimationListener);
    

提交回复
热议问题