如何在android中翻转viewflipper的视图?

问题描述:

在Android应用程序我使用两个视图脚蹼翻转视图。我想提供翻转视图之间的延迟。我正在调用视图脚本上的点击处理程序。这是我的代码。如何在android中翻转viewflipper的视图?

@Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.oldmactwo); 

      flipper = (ViewFlipper) findViewById(R.id.jetViewflipper); 
      flippercow=(ViewFlipper) findViewById(R.id.cowViewflipper); 

      flippercow.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
     Toast.makeText(getApplicationContext(), "on click method call",Toast.LENGTH_SHORT).show();    

     try { 
      Thread.sleep(1000); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
        flipper.setInAnimation(inFromLeftAnimation()); 
        flipper.setOutAnimation(outToLeftAnimation()); 
        flipper.showPrevious(); 

        try { 
         Thread.sleep(1000); 
        } catch (InterruptedException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
        /*Thread splashThread=new Thread() 
        { 
         public void run() { 
          try { 
           sleep(5000); 
          } catch (InterruptedException e) { 
           // TODO: handle exception 
          } 
          finally{ 
           //splashThread.stop(); 
          } 

         }; 
        }; 
        splashThread.start();*/ 

    Toast.makeText(getApplicationContext(), "delay ends",Toast.LENGTH_SHORT).show();     
        //getcowFlipper();    
        flippercow.setInAnimation(inFromBottomAnimation()); 
        flippercow.setOutAnimation(outToTopAnimation()); 
        flippercow.showNext(); 
        //flipper.showPrevious(); 
    Toast.makeText(getApplicationContext(), "method ends",Toast.LENGTH_SHORT).show();    

       } 
      }); 
    } 

在上面的代码中,首先执行延迟,然后再查看翻转。

+0

使用[CountDownTimer(http://developer.android.com/reference/android/os/CountDownTimer.html)和做在onTick或Handler和postDelay中翻转 – Selvin

+0

重新考虑使用ViewFlipper,我像第一次一样使用它。您应该查看Android开发人员网站上的startActivity()方法和Intent对象。 – Jordy

你inFromLeftAnimation()+ inFromRightAnimation()+ outFromLeftAnimation()+ outFromRightAnimation()方法中包含一部分这样的:

inFromLeft.setDuration(400); 

以上部分将给出一个400毫秒的延迟。 Ofcourse,你也得到了inFromRight,outFromLeft等

例子:

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(400); 
     inFromLeft.setInterpolator(new AccelerateInterpolator()); 
     return inFromLeft; 
    } 
+0

我不认为他问如何延迟动画,但如何延迟视图翻转... – Selvin

+0

出现了他做到了。 – Jordy