我的活动中有一个滑动抽屉,我从下往上滑动手势滑动抽屉我想要的是在一秒钟后关闭打开的抽屉或延迟5秒后说。我怎么能这样做?
private class GestureDetector extends SimpleOnGestureListener {
SlidingDrawer drawer;
Timer timer;
public GestureDetector(SlidingDrawer drawer) {
this.drawer = drawer;
timer = new Timer();
}
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
closeSlider();
}
};
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1.getY() > e2.getY()) {
this.drawer.animateOpen();
timer.scheduleAtFixedRate( timerTask , 0, 3000);
} else {
//this.drawer.animateClose();
}
}
public void closeSlider() {
this.drawer.animateClose();
}
}
//i call it on activity onCreate()
SlidingDrawer slidingDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
new GestureDetector(slidingDrawer);
感谢你
答案 0 :(得分:2)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO call closeSlider method here.
}
}, 5000);