gpt4 book ai didi

android - 如何在android中通过viewflipper翻转 View ?

转载 作者:行者123 更新时间:2023-11-30 04:27:26 25 4
gpt4 key购买 nike

在 android 应用程序中,我使用两个 View 翻转器来翻转 View 。我想提供翻转 View 之间的延迟。我正在调用 View 翻转器上的单击处理程序。这是我的代码。

@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();

}
});
}

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

最佳答案

您的 inFromLeftAnimation() + inFromRightAnimation() + outFromLeftAnimation() + outFromRightAnimation() 方法包含如下部分:

inFromLeft.setDuration(400);

以上部分会产生 400 毫秒的延迟。当然你也有 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;
}

关于android - 如何在android中通过viewflipper翻转 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8242391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com