如何更改google map v2中默认缩放控制按钮的外观?

时间:2016-04-07 19:57:20

标签: android google-maps viewlayout

我可以按如下方式访问默认缩放控制的放大和缩小按钮:

View zoomControls = mapFragment.getView().findViewById(0x1);

    for(int i=0;i<((ViewGroup)zoomControls).getChildCount();i++){
        View child=((ViewGroup)zoomControls).getChildAt(i);
        if (i==0) {
            btn_zoomIn = child;
            // there is your "+" button, zoom in
            child.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()){
                        case MotionEvent.ACTION_DOWN:
                            updateZoom = new ZoomInMapThread();
                            updateZoom.start();
                            break;
                        case MotionEvent.ACTION_UP:
                            updateZoom.interrupt();
                            zoomingIn++;
                            break;
                    }
                    return true;
                }
            });
        }
        if (i==1) {
            btn_zoomOut = child;
            // there is your "+" button, zoom in
            child.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()){
                        case MotionEvent.ACTION_DOWN:
                            updateZoom = new ZoomOutMapThread();
                            updateZoom.start();
                            break;
                        case MotionEvent.ACTION_UP:
                            updateZoom.interrupt();
                            zoomingOut++;
                            break;
                    }
                    return true;
                }
            });
        }
    }

我在这里启动线程,在按下按钮时通过放大或缩小来更新UI。我想要做的是,当用户到达maxZoom / minZoom时,更改按钮的外观。这里是放大/缩小线程的代码:

    private class ZoomOutMapThread extends Thread {
    @Override
    public void run(){
        try {
            while (!Thread.currentThread().isInterrupted()){
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        currentZoomLevel = currentZoomLevel - 0.1f;
                        if (currentZoomLevel < minZoom){
                            currentZoomLevel = minZoom;
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.INVISIBLE);
                        } else {
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        }
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel));
                        Log.d("Zoom", "Level:" + currentZoomLevel);
                    }
                });
                Thread.sleep(100);
            }
        } catch (InterruptedException consumed) {
            consumed.printStackTrace();
        }
    }
}

private class ZoomInMapThread extends Thread {
    @Override
    public void run(){
        try {
            while (!Thread.currentThread().isInterrupted()){
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        currentZoomLevel = currentZoomLevel + 0.1f;
                        if (currentZoomLevel > maxZoom){
                            currentZoomLevel = maxZoom;
                            btn_zoomIn.setVisibility(View.INVISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        } else {
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        }
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel));
                        Log.d("Zoom","Level:"+currentZoomLevel);
                    }
                });
                Thread.sleep(100);
            }
        } catch (InterruptedException consumed) {
            consumed.printStackTrace();
        }
    }
}

现在,我将它设置为隐形,但我希望它看起来像一个禁用/不可点击的按钮。关于如何在像这里的一般视图上做到这一点的任何想法?

0 个答案:

没有答案