1、Handler延迟2s执行一个runnable
Handler handler=new Handler(); Runnable runnable=new Runnable() { @Override public void run() { // TODO Auto-generated method stub if(xsLayout.getVisibility()==View.VISIBLE){ xsLayout.setVisibility(View.GONE); } } }; handler.postDelayed(runnable, 2000);
2、在runnable被执行之前取消这个定时任务
handler.removeCallbacks(runnable);
Done!