2011-11-23 46 views
2

在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

回答

1

你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