Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图片段+;残缺的雷达拒绝协调_Android_Android Fragments - Fatal编程技术网

Android 谷歌地图片段+;残缺的雷达拒绝协调

Android 谷歌地图片段+;残缺的雷达拒绝协调,android,android-fragments,Android,Android Fragments,我这里有一个简单的场景 案例 1) 可容纳三个片段的FragmentStateAdapter @Override public Fragment getItem(int position) { Fragment fragment = null; switch (position) { case 0: fragment=new LocationFragment(); break; case 1: fragme

我这里有一个简单的场景

案例

1) 可容纳三个片段的FragmentStateAdapter

    @Override
public Fragment getItem(int position) {

    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment=new LocationFragment();
        break;
    case 1:
        fragment=new CongestFrag();
        break;
    case 2:
        fragment=new SubcribedFrag();
        break;
    default:
        break;
    }
    return fragment;
}
顾名思义,位置片段将包含一个谷歌地图片段。这方面的XML应该是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/off_white"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/fragment_title"
    android:layout_width="@dimen/fragments_title_view_width"
    android:layout_height="@dimen/fragments_title_view_height"
    android:text="@string/location_fragment_title" 
    android:textSize="@dimen/fragments_title_text_size"
    android:fontFamily="sans-serif-light"/>

<fragment 
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/>
当我从片段列表的底部走向LocationFragment时,这是中断的代码(LocationFragment.java)

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    mFragmentView =inflater.inflate(R.layout.location_fragment, container, false);

                //code breaks above 

     mMap.addMarker(new MarkerOptions().position(new LatLng(Globals.LocationFragment.DEFAULT_LAT, Globals.LocationFragment.DEFAULT_LONG)).title("Marker"));
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Globals.LocationFragment.DEFAULT_LAT, Globals.LocationFragment.DEFAULT_LONG), 8.0f));

    /*Just a container to keep the width and height . See usage*/
    mSize = new Point();


    initProperties();
    initControls();
    return mFragmentView;
}
投机 看起来这个片段之前没有被正确地销毁,android两次膨胀了相同的视图。但这当然并没有意义。请在这方面帮助我


谢谢

我复制了。我发现类似的帖子已经有了很多解决方案。应该研究得更好。如果有人感兴趣,这里是链接“

”我们都知道,当我们在片段列表中前进或后退时,viewpager会巧妙地销毁和重新创建片段”——不,它不会
ViewPager
对片段一无所知
FragmentPagerAdapter
FragmentStatePagerAdapter
知道碎片,只有后者会基于页面导航销毁和重新创建这些碎片。我不希望它只用三页就能毁掉任何东西
    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    mFragmentView =inflater.inflate(R.layout.location_fragment, container, false);

                //code breaks above 

     mMap.addMarker(new MarkerOptions().position(new LatLng(Globals.LocationFragment.DEFAULT_LAT, Globals.LocationFragment.DEFAULT_LONG)).title("Marker"));
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Globals.LocationFragment.DEFAULT_LAT, Globals.LocationFragment.DEFAULT_LONG), 8.0f));

    /*Just a container to keep the width and height . See usage*/
    mSize = new Point();


    initProperties();
    initControls();
    return mFragmentView;
}