Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

Android Studio Google Map V2 fragment rendering

I tried to write a test demo for Google Map V2 in Android Studio. I followed every step from Androidhive Google Map V2 or better I think I need.

I'm using the same layout_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

</RelativeLayout>

but I'm getting always the same rendering problem:

Rendering Problems
A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...

I have absolutely no idea what's the problem. Did I forget something? I just need to add Google services in the build.gradle like

compile 'com.google.android.gms:play-services:4.4.52'

I copied the manifest from the demo and changed the API Key.

question from:https://stackoverflow.com/questions/23898992/android-studio-google-map-v2-fragment-rendering

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The accepted answer is not wrong but it does not help.

As Dan wrote, Android Studio (also Version 1.0) will not display the map.
Maps needs an API key and dynamic processed code, maybe some day we will have that but so far not.
I've a 5 minute solution for those who want to see their app properly in layout preview: enter image description here

To properly develop I still needed something else than a blank background.
I added overlays and buttons on top of the map, I really needed to see the map while placing elements over it.
The solution is simple:
1. Make a screenshot of your app with the map running (Power + Volume Down)
2. Download the screenshot and use an image editor to remove the top and bottom UI elements, so you will end up with only the map itself as an image.
3. Import that image into android studio drawables
4. create a new layout, name it dummy_mapviewfragment, put only a linearlayout and an imageview in
5. make the imageview "fill" the parent, and set "src" to the cropped image you just imported
6. back to your layout, add this into your Mapview Fragment xml :

 tools:layout="@layout/dummy_mapviewfragment"/>

That's it, now you will have a non-interactive mapview fragment which displays a real map.
Your app will look like it looks on your mobile phone. If you made errors in your image cropping you can "fix" it by setting the image scale to "centerCrop" so it will properly stretch out.

Update: You can get a screenshot without need to crop directly from within Androidstudio! Makes it a bit more convenient ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...