第二个视图的 viewflipper 问题

发布于 2024-11-10 00:34:08 字数 10639 浏览 3 评论 0原文

我是 Android 新手,无法解决视图翻转器的问题。当我单击第二个视图中的按钮时,第三个视图应该出现并带有 infromright() 动画。但与此同时,第一个视图也与第三个视图一起出现,并在内部翻译并消失。这不应该发生

如何阻止这种情况,

这里的任何想法都是代码

public class gif extends Activity {
    ViewFlipper flipper;
  //    RelativeLayout r1 = (RelativeLayout)findViewById(R.id.second_view);



    private Animation inFromTopAnimation() {

    Animation inFromTop = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
    Animation.RELATIVE_TO_PARENT,  -1.0f, Animation.RELATIVE_TO_PARENT,   0.0f
    );
    inFromTop.setDuration(1000);
    inFromTop.setInterpolator(new AccelerateInterpolator());
    return inFromTop;
    }
    private Animation outToBottomAnimation() {
    Animation outtoBottom = new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  +1.0f
    );
    outtoBottom.setDuration(1000);
    outtoBottom.setInterpolator(new AccelerateInterpolator());
    return outtoBottom;
    }

    private Animation outToTopAnimation() {
    Animation inFromTop = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
    Animation.RELATIVE_TO_PARENT,  +1.0f, Animation.RELATIVE_TO_PARENT,   0.0f
    );
    inFromTop.setDuration(1000);
    inFromTop.setInterpolator(new AccelerateInterpolator());
    return inFromTop;
    }
    private Animation outFromBottomAnimation() {
    Animation outFromBottom = new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f
    );
    outFromBottom.setDuration(1000);
    outFromBottom.setInterpolator(new AccelerateInterpolator());
    return outFromBottom;
    }



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     flipper = (ViewFlipper) findViewById(R.id.flipper);
     ImageView imgview1 = (ImageView) findViewById(R.id.imageview1);

     Button button2 = (Button) findViewById(R.id.flipback);

     imgview1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
             flipper.setInAnimation(inFromTopAnimation());
             flipper.setOutAnimation(outToBottomAnimation());
             flipper.showNext();      
         }
     });

     button2.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
             flipper.setInAnimation(outToTopAnimation());
             flipper.setOutAnimation(outFromBottomAnimation());
             flipper.showPrevious();

         }

     });


    }

     @Override
     public  void  onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
     ImageView imgview1 = (ImageView)findViewById(R.id.imageview1);                                        
     imgview1.setVisibility(ImageView.VISIBLE);
     imgview1.setBackgroundResource(R.anim.topimageview);

     AnimationDrawable frameAnimation =
     (AnimationDrawable) imgview1.getBackground();

     if (frameAnimation.isRunning()) {
        frameAnimation.stop();
     }

     else {
        frameAnimation.stop();
        frameAnimation.start();
     }

     ImageView imgview2 = (ImageView)findViewById(R.id.imageview2);                                        
     imgview2.setVisibility(ImageView.VISIBLE);
     imgview2.setBackgroundResource(R.anim.rectbackground);

     AnimationDrawable frameAnimation1 =
     (AnimationDrawable) imgview2.getBackground();

     if (frameAnimation1.isRunning()) {
        frameAnimation1.stop();
     }

     else {
        frameAnimation1.stop();
        frameAnimation1.start();
     } 
     ImageView imgview3 = (ImageView)findViewById(R.id.imageview3);                                        
     imgview3.setVisibility(ImageView.VISIBLE);
     imgview3.setBackgroundResource(R.anim.background1);

     AnimationDrawable frameAnimation2 =
     (AnimationDrawable) imgview3.getBackground();

     if (frameAnimation2.isRunning()) {
        frameAnimation2.stop();
     }

     else {
        frameAnimation2.stop();
        frameAnimation2.start();
     }
     ImageView imgView = (ImageView)findViewById(R.id.imageview01);                                        
     imgView.setVisibility(ImageView.VISIBLE);
     imgView.setBackgroundResource(R.anim.background);

     AnimationDrawable frameAnimation3 =
     (AnimationDrawable) imgView.getBackground();

     if (frameAnimation3.isRunning()) {
        frameAnimation3.stop();
     }

     else {
        frameAnimation3.stop();
        frameAnimation3.start();
     }
     ImageView imgview02 = (ImageView)findViewById(R.id.imageview02);                                        
     imgview02.setVisibility(ImageView.VISIBLE);
     imgview02.setBackgroundResource(R.anim.background3);

     AnimationDrawable frameAnimation5 =
     (AnimationDrawable) imgview02.getBackground();

     if (frameAnimation5.isRunning()) {
        frameAnimation5.stop();
     }

     else {
        frameAnimation5.stop();
        frameAnimation5.start();
     }

     ImageView imgview03 = (ImageView)findViewById(R.id.imageview03);                                        
     imgview03.setVisibility(ImageView.VISIBLE);
     imgview03.setBackgroundResource(R.anim.background2);

     AnimationDrawable frameAnimation4 =
     (AnimationDrawable) imgview03.getBackground();

     if (frameAnimation4.isRunning()) {
        frameAnimation4.stop();
     }

     else {
        frameAnimation4.stop();
        frameAnimation4.start();
     }

     ImageView imgview04 = (ImageView)findViewById(R.id.imageview4);                                        
     imgview04.setVisibility(ImageView.VISIBLE);
     imgview04.setBackgroundResource(R.anim.background4);

     AnimationDrawable frameAnimation6 =
     (AnimationDrawable) imgview04.getBackground();

     if (frameAnimation6.isRunning()) {
        frameAnimation6.stop();
     }

     else {
        frameAnimation6.stop();
        frameAnimation6.start();
     }
    ;
    final ImageView hearttap =(ImageView)findViewById(R.id.hearttap);
  // final View second = null ;

    Button ekgbutton = (Button)findViewById(R.id.ekgbutton);

    final ImageView i2 = (ImageView) findViewById(R.id.imageview02);
     final ImageView i3 = (ImageView) findViewById(R.id.imageview03);
     final ImageView i4 = (ImageView) findViewById(R.id.imageview04);
     final ImageView i5 = (ImageView) findViewById(R.id.imageview05);
     final ImageView i6 = (ImageView) findViewById(R.id.imageview06);
     final ImageView i7 = (ImageView) findViewById(R.id.imageview07);


    hearttap.setOnTouchListener(new View.OnTouchListener() {

        private Animation inFromRightAnimation() {

            Animation inFromRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,  +1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
            Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f

            );
            inFromRight.setDuration(500);
            inFromRight.setInterpolator(new AccelerateInterpolator());
            return inFromRight;
            }
            private Animation outToLeftAnimation() {
            Animation outtoLeft = new TranslateAnimation(
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f,
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            outtoLeft.setDuration(500);
            outtoLeft.setInterpolator(new AccelerateInterpolator());
            return outtoLeft;
            }


        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
        //  r1.setVisibility(View.GONE);

            i2.setVisibility(View.GONE);
            i3.setVisibility(View.GONE);
            i4.setVisibility(View.GONE);
            i5.setVisibility(View.GONE);
            i6.setVisibility(View.GONE);
            i7.setVisibility(View.GONE); 



             flipper.setInAnimation(inFromRightAnimation());
             flipper.setOutAnimation(outToLeftAnimation());
             flipper.showNext();

           //  flipper.getChildAt(2)
             flipper.setDisplayedChild(2);


           // WebView  webview1= (WebView)findViewById(R.id.ekgwebview1);
        //   webview1.loadUrl("C://Users/Android/Desktop/bg only.gif");
         // flipper.clearDisappearingChildren();

        // flipper.dispatchWindowVisibilityChanged(2);
             flipper.setEnabled(true);

             if (hearttap.onTouchEvent(event))


                 return true;
             else
                 return false;         

        }
    });

 ekgbutton.setOnTouchListener(new View.OnTouchListener() {
     private Animation inFromLeftAnimation() {
            Animation inFromLeft = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,  -1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
            Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            inFromLeft.setDuration(500);
            inFromLeft.setInterpolator(new AccelerateInterpolator());
            return inFromLeft;
            }
            private Animation outToRightAnimation() {
            Animation outtoRight = new TranslateAnimation(
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  +1.0f,
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            outtoRight.setDuration(500);
            outtoRight.setInterpolator(new AccelerateInterpolator());
            return outtoRight;
            }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            i2.setVisibility(View.GONE);
            i3.setVisibility(View.GONE);
            i4.setVisibility(View.GONE);
            i5.setVisibility(View.GONE);
            i6.setVisibility(View.GONE);
            i7.setVisibility(View.GONE);    

            flipper.setInAnimation(inFromLeftAnimation());
             flipper.setOutAnimation(outToRightAnimation());
             flipper.showPrevious(); 
             flipper.setEnabled(true);

             //  flipper.getChildAt(0);
            flipper.setDisplayedChild(0);

            return true;

        }

    });

    }
    }

I am newbie to android and I couldn't able to solve a problem with the view-flipper. when I click a button in second view the third view should appear with infromright() animation. But at the same time the first view also appearing with the third view and translating inside and disappearing. This should not happen

How to stop this, any Idea

here is the code

public class gif extends Activity {
    ViewFlipper flipper;
  //    RelativeLayout r1 = (RelativeLayout)findViewById(R.id.second_view);



    private Animation inFromTopAnimation() {

    Animation inFromTop = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
    Animation.RELATIVE_TO_PARENT,  -1.0f, Animation.RELATIVE_TO_PARENT,   0.0f
    );
    inFromTop.setDuration(1000);
    inFromTop.setInterpolator(new AccelerateInterpolator());
    return inFromTop;
    }
    private Animation outToBottomAnimation() {
    Animation outtoBottom = new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  +1.0f
    );
    outtoBottom.setDuration(1000);
    outtoBottom.setInterpolator(new AccelerateInterpolator());
    return outtoBottom;
    }

    private Animation outToTopAnimation() {
    Animation inFromTop = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
    Animation.RELATIVE_TO_PARENT,  +1.0f, Animation.RELATIVE_TO_PARENT,   0.0f
    );
    inFromTop.setDuration(1000);
    inFromTop.setInterpolator(new AccelerateInterpolator());
    return inFromTop;
    }
    private Animation outFromBottomAnimation() {
    Animation outFromBottom = new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
      Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f
    );
    outFromBottom.setDuration(1000);
    outFromBottom.setInterpolator(new AccelerateInterpolator());
    return outFromBottom;
    }



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     flipper = (ViewFlipper) findViewById(R.id.flipper);
     ImageView imgview1 = (ImageView) findViewById(R.id.imageview1);

     Button button2 = (Button) findViewById(R.id.flipback);

     imgview1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
             flipper.setInAnimation(inFromTopAnimation());
             flipper.setOutAnimation(outToBottomAnimation());
             flipper.showNext();      
         }
     });

     button2.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
             flipper.setInAnimation(outToTopAnimation());
             flipper.setOutAnimation(outFromBottomAnimation());
             flipper.showPrevious();

         }

     });


    }

     @Override
     public  void  onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
     ImageView imgview1 = (ImageView)findViewById(R.id.imageview1);                                        
     imgview1.setVisibility(ImageView.VISIBLE);
     imgview1.setBackgroundResource(R.anim.topimageview);

     AnimationDrawable frameAnimation =
     (AnimationDrawable) imgview1.getBackground();

     if (frameAnimation.isRunning()) {
        frameAnimation.stop();
     }

     else {
        frameAnimation.stop();
        frameAnimation.start();
     }

     ImageView imgview2 = (ImageView)findViewById(R.id.imageview2);                                        
     imgview2.setVisibility(ImageView.VISIBLE);
     imgview2.setBackgroundResource(R.anim.rectbackground);

     AnimationDrawable frameAnimation1 =
     (AnimationDrawable) imgview2.getBackground();

     if (frameAnimation1.isRunning()) {
        frameAnimation1.stop();
     }

     else {
        frameAnimation1.stop();
        frameAnimation1.start();
     } 
     ImageView imgview3 = (ImageView)findViewById(R.id.imageview3);                                        
     imgview3.setVisibility(ImageView.VISIBLE);
     imgview3.setBackgroundResource(R.anim.background1);

     AnimationDrawable frameAnimation2 =
     (AnimationDrawable) imgview3.getBackground();

     if (frameAnimation2.isRunning()) {
        frameAnimation2.stop();
     }

     else {
        frameAnimation2.stop();
        frameAnimation2.start();
     }
     ImageView imgView = (ImageView)findViewById(R.id.imageview01);                                        
     imgView.setVisibility(ImageView.VISIBLE);
     imgView.setBackgroundResource(R.anim.background);

     AnimationDrawable frameAnimation3 =
     (AnimationDrawable) imgView.getBackground();

     if (frameAnimation3.isRunning()) {
        frameAnimation3.stop();
     }

     else {
        frameAnimation3.stop();
        frameAnimation3.start();
     }
     ImageView imgview02 = (ImageView)findViewById(R.id.imageview02);                                        
     imgview02.setVisibility(ImageView.VISIBLE);
     imgview02.setBackgroundResource(R.anim.background3);

     AnimationDrawable frameAnimation5 =
     (AnimationDrawable) imgview02.getBackground();

     if (frameAnimation5.isRunning()) {
        frameAnimation5.stop();
     }

     else {
        frameAnimation5.stop();
        frameAnimation5.start();
     }

     ImageView imgview03 = (ImageView)findViewById(R.id.imageview03);                                        
     imgview03.setVisibility(ImageView.VISIBLE);
     imgview03.setBackgroundResource(R.anim.background2);

     AnimationDrawable frameAnimation4 =
     (AnimationDrawable) imgview03.getBackground();

     if (frameAnimation4.isRunning()) {
        frameAnimation4.stop();
     }

     else {
        frameAnimation4.stop();
        frameAnimation4.start();
     }

     ImageView imgview04 = (ImageView)findViewById(R.id.imageview4);                                        
     imgview04.setVisibility(ImageView.VISIBLE);
     imgview04.setBackgroundResource(R.anim.background4);

     AnimationDrawable frameAnimation6 =
     (AnimationDrawable) imgview04.getBackground();

     if (frameAnimation6.isRunning()) {
        frameAnimation6.stop();
     }

     else {
        frameAnimation6.stop();
        frameAnimation6.start();
     }
    ;
    final ImageView hearttap =(ImageView)findViewById(R.id.hearttap);
  // final View second = null ;

    Button ekgbutton = (Button)findViewById(R.id.ekgbutton);

    final ImageView i2 = (ImageView) findViewById(R.id.imageview02);
     final ImageView i3 = (ImageView) findViewById(R.id.imageview03);
     final ImageView i4 = (ImageView) findViewById(R.id.imageview04);
     final ImageView i5 = (ImageView) findViewById(R.id.imageview05);
     final ImageView i6 = (ImageView) findViewById(R.id.imageview06);
     final ImageView i7 = (ImageView) findViewById(R.id.imageview07);


    hearttap.setOnTouchListener(new View.OnTouchListener() {

        private Animation inFromRightAnimation() {

            Animation inFromRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,  +1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
            Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f

            );
            inFromRight.setDuration(500);
            inFromRight.setInterpolator(new AccelerateInterpolator());
            return inFromRight;
            }
            private Animation outToLeftAnimation() {
            Animation outtoLeft = new TranslateAnimation(
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f,
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            outtoLeft.setDuration(500);
            outtoLeft.setInterpolator(new AccelerateInterpolator());
            return outtoLeft;
            }


        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
        //  r1.setVisibility(View.GONE);

            i2.setVisibility(View.GONE);
            i3.setVisibility(View.GONE);
            i4.setVisibility(View.GONE);
            i5.setVisibility(View.GONE);
            i6.setVisibility(View.GONE);
            i7.setVisibility(View.GONE); 



             flipper.setInAnimation(inFromRightAnimation());
             flipper.setOutAnimation(outToLeftAnimation());
             flipper.showNext();

           //  flipper.getChildAt(2)
             flipper.setDisplayedChild(2);


           // WebView  webview1= (WebView)findViewById(R.id.ekgwebview1);
        //   webview1.loadUrl("C://Users/Android/Desktop/bg only.gif");
         // flipper.clearDisappearingChildren();

        // flipper.dispatchWindowVisibilityChanged(2);
             flipper.setEnabled(true);

             if (hearttap.onTouchEvent(event))


                 return true;
             else
                 return false;         

        }
    });

 ekgbutton.setOnTouchListener(new View.OnTouchListener() {
     private Animation inFromLeftAnimation() {
            Animation inFromLeft = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,  -1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
            Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            inFromLeft.setDuration(500);
            inFromLeft.setInterpolator(new AccelerateInterpolator());
            return inFromLeft;
            }
            private Animation outToRightAnimation() {
            Animation outtoRight = new TranslateAnimation(
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  +1.0f,
             Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
            );
            outtoRight.setDuration(500);
            outtoRight.setInterpolator(new AccelerateInterpolator());
            return outtoRight;
            }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            i2.setVisibility(View.GONE);
            i3.setVisibility(View.GONE);
            i4.setVisibility(View.GONE);
            i5.setVisibility(View.GONE);
            i6.setVisibility(View.GONE);
            i7.setVisibility(View.GONE);    

            flipper.setInAnimation(inFromLeftAnimation());
             flipper.setOutAnimation(outToRightAnimation());
             flipper.showPrevious(); 
             flipper.setEnabled(true);

             //  flipper.getChildAt(0);
            flipper.setDisplayedChild(0);

            return true;

        }

    });

    }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文