嵌套的GoogleMap V2手势传播

时间:2013-06-06 18:26:26

标签: android google-maps navigation zooming gestures

我正在将GooglepMap V2嵌入到我的Android APP(2.2)中,但是当我尝试进行缩放或导航到我的设备中的地图时,移动速度太慢,有时事件(缩放或导航)不会不行。我传播这个事件可能有问题吗?这可能是问题吗?

布局图:

<RelativeLayout  
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>

GoogleMapActivity:

public class GoogleMapActivity extends FragmentActivity{

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.template);
    LinearLayout l = (LinearLayout)  findViewById(R.id.info);
    LinearLayout left = new LinearLayout(this);
    ...
    LinearLayout right = new LinearLayout(this);
    ...
    addMap(right);   
    l.addView(right);
}

RelativeLayout mapRelative;
private final LatLng UPV = new LatLng(39.481106, -0.340987);
private GoogleMap mapa;

public void addMap(LinearLayout main){      
    LayoutInflater inflater = LayoutInflater.from(GoogleMapActivity.this);
    mapRelative = (RelativeLayout)inflater.inflate(R.layout.map, null, false);
    main.addView(mapRelative);
}

@Override
protected void onResume() {
    super.onResume();

    mapa = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
    .getMap();
    if (mapa != null) {
      mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(UPV, 15));
      mapa.setMyLocationEnabled(true);
      mapa.getUiSettings().setAllGesturesEnabled(true);
}
}
}

1 个答案:

答案 0 :(得分:0)

我发现了问题!我正在使用“R.layout.template”将Map嵌套到ScrollView中。然后我删除了ScrollView。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >   
<LinearLayout 
    android:id="@+id/info"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:focusableInTouchMode="true"
>
</LinearLayout>
</ScrollView>