我的应用程序包含一个带有一些图像的VIEwFlipper.当应用程序启动时,VIEwFlipper startflipPing().当用户触摸屏幕VIEwFlipper stopflipPing()时.我必须在最后一次触摸60秒后执行此 *** 作,VIEwFlipper再次开始翻转.我的类实现ontouchListener,我有这个方法ontouch:
public boolean ontouch(VIEw arg0, MotionEvent arg1) { switch (arg1.getAction()) { case MotionEvent.ACTION_DOWN: { downXValue = arg1.getX(); break; } case MotionEvent.ACTION_UP: { currentX = arg1.getX(); if (downXValue < currentX) { // Set the animation vf.stopFlipPing(); vf.setoutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in)); // Flip! vf.showPrevIoUs(); } if (downXValue > currentX) { // Set the animation vf.stopFlipPing(); vf.setoutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); // Flip! vf.showNext(); } if (downXValue == currentX) { final int IDImage = arg0.getID(); vf.stopFlipPing(); System.out.println("ID" + IDImage); System.out.println("last touch "+getTimeOfLastEvent()); } break; } } // if you return false, these actions will not be recorded return true; }
我发现了这种方法,用于找到最后一次触摸的时间:
static long timeLastEvent=0;public long getTimeOfLastEvent() { long duration = System.currentTimeMillis() - timeLastEvent; timeLastEvent = System.currentTimeMillis(); return duration; }
我的问题是:我应该在哪里调用getTimeOfLastEvent()?如果我把它放在ontouch()上,我将永远不会抓住getTimeOfLastEvent == 60000的那一刻,对吧?
解决方法:
你应该做的是创建一个Handler
(应该是你的Activity的一个实例变量,应该在onCreate期间初始化):
Handler myHandler = new Handler();
此外,您还需要一个可以再次开始翻转的Runnable(也需要在您的Activity中声明):
private Runnable flipController = new Runnable() { @OverrIDe public voID run() { vf.startFlipPing(); }};
然后在你的onClick中你只需在Handler上发布Runnable但延迟了60秒:
myHandler.postDelayed( flipController, 60000 );
将其延迟发布意味着:“在60秒内运行此代码”.
总结以上是内存溢出为你收集整理的android – 从最后一次触摸开始60秒后,ViewFlipper的StartFlipping全部内容,希望文章能够帮你解决android – 从最后一次触摸开始60秒后,ViewFlipper的StartFlipping所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)