1 android google-maps android-fragments supportmapfragment
我已经将android SDK更新为5.0,而我之前的项目没有使用它(它在4.4.2中正常工作).
我有一个扩展片段的类
public class MapFragment extends Fragment{
//
}
Run Code Online (Sandbox Code Playgroud)
在这个课程中,我用google support mapfragment夸大了一个布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_tile_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" >
<RelativeLayout
android:id="@+id/full_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<Textview
<!-- dfh
fgh -->
/>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我在我的代码中执行此操作时,它返回null
SupportMapFragment fragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)
在Android4.4.2中这条线路对我有用,但在更新后有一些问题......
有没有人找到解决方案......
小智 9
我找到了答案,它对我有用
而不是这个
SupportMapFragment fragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)
我改变了
SupportMapFragment fragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1762 次 |
| 最近记录: |