我必须在scrollview中显示地图我能够显示地图但是当我滚动屏幕时,地图正在消失。我附加了屏幕截图。
代码:
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
_myMap = mySupportMapFragment.getMap();
XML:
<RelativeLayout
android:id="@+id/map_contact_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_toLeftOf="@+id/grid_layout"
android:layout_weight="1" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
答案 0 :(得分:0)
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