【问题标题】:Nested GoogleMap V2 Gestures Propagation嵌套的 GoogleMap V2 手势传播
【发布时间】:2013-06-06 18:26:26
【问题描述】:

我正在将 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>

谷歌地图活动:

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);
}
}
}

【问题讨论】:

  • 为什么要添加两次地图?您已经在 xml 中将其声明为静态片段,您无需在 addMap 方法中再次添加它
  • 我有两 (2) 个 xml,主 xml 名为 R.layout.template(应用程序的通用视图)和 R.layout.map 用于我想包含在第一个中的 Googlemap使用 addMap
  • 但您仍在添加 2 张地图,这可能是您的问题。摆脱在您已在 xml 中添加的代码中添加地图

标签: android google-maps navigation zooming gestures


【解决方案1】:

我发现了问题!我正在使用“R.layout.template”将地图嵌套到 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2012-10-20
    • 1970-01-01
    • 2020-11-25
    相关资源
    最近更新 更多