在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();
}
});
}
在上面的代碼中,首先執行延遲,然後再查看翻轉。
使用[CountDownTimer(http://developer.android.com/reference/android/os/CountDownTimer.html)和做在onTick或Handler和postDelay中翻轉 – Selvin
重新考慮使用ViewFlipper,我像第一次一樣使用它。您應該查看Android開發人員網站上的startActivity()方法和Intent對象。 – Jordy