Search code examples
androidgoogle-maps-api-2

Not able to scroll Google map with API v2 Horizontally


I am developing an application in which I have integrated Google map API v2. There is a sliding menu which I have added at runtime using a HorizontalScrollView. The problem is that I am only able to scroll the map vertically, as I try to scroll horizontally the HorizontalScrollView gets the touch event.

This is how I make a layout.

LayoutInflater inflater = LayoutInflater.from(this);
    View menu = inflater.inflate(R.layout.menu, null);

    HorizontalScrollView hsv = new HorizontalScrollView(this) {
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (Menu_Displayed) {
                return false;
            } else {
                return true;
            }
        }
    LinearLayout li_body = new LinearLayout(this);
    li_body.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT));
    li_body.setOrientation(0);
    li_body.setBackgroundColor(Color.TRANSPARENT);

    hsv.addView(li_body);

    TextView placeholder = new TextView(this);
    placeholder.setTextColor(Color.TRANSPARENT);
    placeholder.setLayoutParams(new LayoutParams(width - 130,
            LayoutParams.MATCH_PARENT));
    placeholder.setVisibility(View.INVISIBLE);

    li_body.addView(placeholder);

    LayoutInflater inflatex = LayoutInflater.from(this);
    View mainScreen = inflatex.inflate(R.layout.main, null);
    li_body.addView(mainScreen);


    FrameLayout mainFrame = new FrameLayout(this);
    mainFrame.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT));
    mainFrame.addView(menu);
    mainFrame.addView(hsv);

    hsv.post(new Runnable() {

        @Override
        public void run() {
            hsv.scrollBy(width - 130, 0);
        }
    });
    setContentView(mainFrame);

The View mainScreen has a fragment for the map. Any solution so that the I can scroll the map horizontally?


Solution

  • Try combining these parameters:

    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    

    or

    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    

    and the other parameter:

    getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
    

    or

    getSlidingMenu().setMode(SlidingMenu.LEFT); / getSlidingMenu().setMode(SlidingMenu.RIGHT);
    

    If I recall right, the combination for you would be

    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
    

    hope this helps!