【问题标题】:Android: Google MapView within ViewFlipperAndroid:ViewFlipper 中的 Google MapView
【发布时间】:2011-09-06 13:17:20
【问题描述】:

我有一个布局,它使用 ViewFlipper 使标签栏在整个应用程序中始终可见。

主要活动扩展了 TabActivity。对于我的一个观点,我想要一个地图视图,我试过这段代码没有成功:

<ViewFlipper android:id="@+id/layout_tab_one"
                android:layout_width="fill_parent" android:layout_height="fill_parent">

                <ListView android:id="@+id/listview" 
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />

                <com.google.android.maps.MapView
                 android:id="@+id/mapview"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:clickable="true"
                 android:apiKey="myapikey">
                  </com.google.android.maps.MapView>  
                <ListView android:id="@+id/lazylistview"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />
                    <include android:id="@+id/cell1" layout="@layout/detail" />
                <ListView android:id="@+id/listview2" 
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />

            </ViewFlipper>

应用程序在启动时崩溃。我已将谷歌地图的用户库放入清单中,并且我也在使用 Google API 运行该应用程序,但仍然没有运气。 有什么建议? 谢谢!

【问题讨论】:

  • 你在 logcat 中遇到了什么错误?
  • ERROR/AndroidRuntime(611):原因:android.view.InflateException:二进制 XML 文件第 18 行:膨胀类 com.google.android.maps.MapView 时出错
  • 添加你的整个堆栈跟踪。它可能会帮助其他人找出问题所在。

标签: android maps android-mapview


【解决方案1】:

您的设备或模拟器没有 Google 地图,或者您可能从 MapActivity 以外的其他东西夸大此布局。

【讨论】:

    【解决方案2】:

    请在初始化 ViewFlipper 的 Activity 上使用 extends FragmentActivity

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:id="@+id/RelativeLayout02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
    
            <ViewFlipper
                android:id="@+id/flipper"
                android:layout_width="fill_parent"
                android:layout_height="400dp" >
    
                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >
    
                    <fragment
                        android:id="@+id/map"
                        android:name="com.google.android.gms.maps.SupportMapFragment"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />
                </RelativeLayout>           
            </ViewFlipper>
        </RelativeLayout>
    </LinearLayout>
    

    并使用下面的代码

    int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());  
    
            if (checkGooglePlayServices != ConnectionResult.SUCCESS) { 
                GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, (Activity) context, 1122).show();
                return;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 2020-04-18
      相关资源
      最近更新 更多