I am trying to do a tab layout same in Play Store. I got to display the tab layout using a fragments and viewpager from androidhive. However, I can't implement google maps v2 on it. I searched the internet for hours already, but I can't find a tutorial on how to do it. Can some one please show me how?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
i just create MapActivity and inflate it to fragment . MapActivity.java:
activity_map.xml:
MapFragment.java:-
Dynamically adding map fragment to view Pager:
If you are targeting an application earlier than API level 12 make an instance of SupportedMapFragment and add it to your view page adapter.
API level 12 or higher support MapFragment objects
When you add yor map use:
instead of
.add
and instead ofgetFragmentManager
.By using this code we can setup MapView anywhere, inside any ViewPager or Fragment or Activity.
In the latest update of Google for Maps, only MapView is supported for fragments. MapFragment & SupportMapFragment doesn't work. I might be wrong but this is what I saw after trying to implement MapFragment & SupportMapFragment.
Setting up the layout for showing the map in the file
location_fragment.xml
:Now, we code the Java class for showing the map in the file
MapViewFragment.java
:Finally you need to get the API Key for your app by registering your app at Google Cloud Console. Register your app as Native Android App.
According to https://developer.android.com/about/versions/android-4.2.html#NestedFragments, you can use nested fragments to achieve this by calling getChildFragmentManager() if you still want to use the Google Maps fragment instead of the view inside your own fragment:
where "content" is the root layout in your fragment (preferably a FrameLayout). The advantage of using a map fragment is that then the map lifecycle is managed automatically by the system.
Although the documentation says "You cannot inflate a layout into a fragment when that layout includes a <fragment>. Nested fragments are only supported when added to a fragment dynamically. ", I have somehow successfully done this and it worked fine. Here is my code:
In the fragment's onCreateView() method:
In the layout:
Hope it helps!
The following approach works for me.
fragment_location_info.xml