我已将地图片段放置在 LinearLayout 中,它是 ScrollView 的子项。当我向下滚动时遇到地图时,地图会在屏幕上留下黑色斑块。我在 ICS 即之前的设备中面临这个问题。姜饼。有没有人遇到过类似的问题?
问问题
397 次
1 回答
1
我得到了解决方案!
创建一个类 MyMapFragment
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.SupportMapFragment;
public class MyMapFragment extends SupportMapFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
setMapTransparent((ViewGroup) view);
return view;
};
private void setMapTransparent(ViewGroup group) {
int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = group.getChildAt(i);
if (child instanceof ViewGroup) {
setMapTransparent((ViewGroup) child);
} else if (child instanceof SurfaceView) {
child.setBackgroundColor(0x00000000);
}
}
}
}
初始化谷歌地图
map = ((MyMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapView)).getMap();
里面的xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_marginBottom="15dp"
android:background="@drawable/mapouter" >
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:name="com.example.MyMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
于 2013-05-16T14:18:27.687 回答