有的时候需要将放大缩小控件延时消失

1.初始化控件

ZoomControls zoomer = (ZoomControls) findViewById(R.id.zoomer);

zoomer.hide();

2. 点击屏幕的时候显示放大缩小控件, 并在指定时间后自动隐藏此控件

@Override
            public void onClick(View v) {
                showZoomer(true);
             

            }

3. showZoomer(Boolean b)的实现

 

ZOOM_HIDE_DELAY_MS=3000    //3秒

private void showZoomer(boolean force) {
        if (force || zoomer.getVisibility() != View.VISIBLE) {
            zoomer.show();
            hideZoomAfterMs = SystemClock.uptimeMillis() + ZOOM_HIDE_DELAY_MS;
            mHandler
                    .postAtTime(hideZoomInstance, hideZoomAfterMs + 10);
        }
    }

4.hideZoomInstance的实现

HideZoomRunnable hideZoomInstance = new HideZoomRunnable();

private class HideZoomRunnable implements Runnable {
        public void run() {
            if (SystemClock.uptimeMillis() >= hideZoomAfterMs) {
                zoomer.hide();
            }
        }

    }