开发者

Android: Google MapView within ViewFlipper

I have a layout which uses a ViewFlipper to keep a tabbar visible at all times throughout the app.

The main activity extends TabActivity. For one of my views I want to have a mapview, I have tried this code to no success:

<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>  开发者_JS百科
                <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>

The app crashes on launch. I have put the user library for google maps into the manifest and I am also running the app using the Google API, still no luck. Any suggestions? Thanks!


Either your device or emulator does not have Google Maps, or possibly you are inflating this layout from something other than a MapActivity.


Please use extends FragmentActivity on the activity where your ViewFlipper is initialised

<?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>

and use below code

int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());  

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜