Google Maps Android API V2 blacking out part of layout

前端 未结 8 1446
-上瘾入骨i
-上瘾入骨i 2021-02-04 13:48

I\'m trying to integrate Google Maps Android API v2 into my Android Application. I\'m placing the Google Map in the middle of my layout. It works great when the layout is able t

8条回答
  •  面向向阳花
    2021-02-04 14:27

    I was able to work around the issue with a hack. I extended ScrollView so I could get notified on scroll events. I used the ObservableScrollView implementation from Synchronise ScrollView scroll positions - android.

    I added to my onCreate():

    ObservableScrollView sv = (ObservableScrollView) findViewById(R.id.scroll);
    sv.setScrollViewListener(this);
    

    Then, when I receive a scroll changed event, I toggle the visibility of the whole view, which forces a re-layout, which prevents the black box from appearing.

    public void onScrollChanged(ObservableScrollView sv, int x, int y, int oldx, int oldy) {
        sv.setVisibility(View.GONE);
        sv.setVisibility(View.VISIBLE);
    }
    

    I tried to invalidate() the map view, and toggling the visibility of just the map view, but neither worked. Thankfully toggling the visibility of the whole view doesn't cause any flicker or other strange behavior.

    There probably is a better solution, but at this point, this is the only thing I've found that seems to work.

提交回复
热议问题