9

Ich habe ein Vollbild-Kartenfragment zu einem meiner drei Tabbed-Fragmente hinzugefügt. Alles funktioniert gut, abgesehen von einem Problem, das ich beim Wechseln zwischen den Tabs habe.Wechsel von Fragment mit Kartenfragment lässt einen schwarzen Bildschirm

Jedes Mal, wenn ich vom Fragment mit der Karte zu einem der anderen Fragmente wechsle, bekomme ich einen schwarzen Bildschirm für etwa 0,2 Sekunden. Es scheint ein ähnliches Problem mit den Problemen beim Scrollen in einer Aktivität mit einem Kartenfragment zu sein.

Ich habe versucht, eine transparente Ansicht andere oben auf der Karte, wie andere vorgeschlagen haben, aber es hat nicht geholfen.

Das ist mein xml:

<FrameLayout 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" 
    tools:context=".ParkMapFragment"> 

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

Und dies ist mein Code:

public class ParkMapFragment extends Fragment { 
    public ParkMapFragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_map, container, false); 
    } 

    @Override 
    public void onStart(){ 
     super.onStart(); 

     getActivity().setTitle("Map"); 
    } 

    @Override 
    public void onDestroyView() { 
     super.onDestroyView(); 
     SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fullParkMap); 
     if (mapFragment != null) { 
      getFragmentManager().beginTransaction().remove(mapFragment).commit(); 
     } 
    } 
} 

jemand irgendwelche Vorschläge?

Antwort

2
@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
    SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fullParkMap); 
    if (mapFragment != null) { 
     getFragmentManager().beginTransaction().remove(mapFragment).commit(); 
    } 
} 

Hier entfernen Sie das Fragment, ohne es zu ersetzen. Ich würde .replace stattdessen mit einem neuen Fragment verwenden.

Etwas wie folgt aus:

getFragmentManager().beginTransaction().replace(R.id.your_placeholder, new CustomFragment(), "cstmFragID").commit(); 
+0

Dieser Code [dieses Problem] zu vermeiden ist (http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-comp-google-androi). Es hat keinen Einfluss auf das Problem, das ich leider habe. – user3746428

+0

wo ist der Code, wo Sie .add verwenden, um das Fragment zu ersetzen? –

+0

Ich bin noch ziemlich neu für Android, aber ich denke, 'onCreateView' ersetzt das gesamte Fragment (mit dem Kartenfragment darin)? Die Karte wird definitiv jedes Mal neu geladen, wenn ich zum Fragment zurückkehre, also muss das wohl geschehen sein. – user3746428

1

Dies ist ein knownissue. In der Zwischenzeit können Sie arbeiten, indem Sie eine andere Ansicht oben auf der Karte platzieren, die eine Hintergrundfarbe verwendet, die mit der des Containers identisch ist. Dies sorgt dafür, dass die Karte nahtlos in den Raum kommt, sobald sie fertig ist.

SupportMapFragment mapFragment = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)); 
+1

Das Problem ist nicht mit der Karte erscheint, es ist, wenn ich Fragmente wechseln (es wird für ein paar Millisekunden schwarz). – user3746428

1

Wie Sie immer ersetzen Fragment dann bekommt würde nur einmal erstellt umgehen Karte immer dann für diese sein laden Sie Ihre Karte Fragment, Rest der Zeit nur ein-/auszublenden Ihr Fragment (als ob Sie mit Registerkarten Fragmenten zeigen).

5

Überprüfen Sie, ob die Ansicht null ist, und wenn nicht, entfernen Sie sie aus der übergeordneten Ansicht. Auf diese Weise werden Sie den schwarzen Bildschirm nicht sehen.

Versuchen Sie den folgenden Code.

Fragment:

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.GoogleMap.OnMapClickListener; 
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.view.InflateException; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class ExhibhitionMap2 extends Fragment implements OnMapClickListener,OnMarkerClickListener{ 

    View v; 
    private GoogleMap mMap; 
    FragmentManager fragmentManager; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

    // android = inflater.inflate(R.layout.activity_exhibhition_map, container, false); 

     if (v != null) { 
       ViewGroup parent = (ViewGroup) v.getParent(); 
       if (parent != null) 
        parent.removeView(v); 
      } 
      try { 
       v = inflater.inflate(R.layout.activity_exhibhition_map, container, false); 
      } catch (InflateException e) { 
       /* map is already there, just return view as it is */ 
      } 

     setUpMapIfNeeded();   
     return v; 
    } 

    /***** Sets up the map if it is possible to do so *****/ 
     public void setUpMapIfNeeded() { 
      // Do a null check to confirm that we have not already instantiated the map. 
      if (mMap == null) { 


       mMap = ((SupportMapFragment) this.getChildFragmentManager().findFragmentById(R.id.map2)).getMap(); 

       // Check if we were successful in obtaining the map. 
       if (mMap != null) 
       { 
        mMap.setOnMapClickListener(this); 
        mMap.setOnMarkerClickListener((OnMarkerClickListener) this); 

        MarkerOptions marker = new MarkerOptions().position(new LatLng(36.011513,-115.174853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)) 
          .title("P-1"); 

        MarkerOptions marker01 = new MarkerOptions().position(new LatLng(36.111513,-115.204853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)) 
          .title("P-2"); 

        MarkerOptions marker02 = new MarkerOptions().position(new LatLng(36.051513,-115.154853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)) 
          .title("P-3"); 


        MarkerOptions marker03 = new MarkerOptions().position(new LatLng(36.057513,-115.344853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)) 
          .title("P-4"); 

        MarkerOptions marker1 = new MarkerOptions().position(new LatLng(36.081513,-115.224853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) 
          .title("F-1"); 

        MarkerOptions marker2 = new MarkerOptions().position(new LatLng(36.051513,-115.334853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) 
          .title("F-2"); 

        MarkerOptions marker3 = new MarkerOptions().position(new LatLng(36.101513,-115.124853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) 
          .title("F-1"); 

        MarkerOptions marker4 = new MarkerOptions().position(new LatLng(36.031513,-115.154853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) 
          .title("F-2"); 

        MarkerOptions marker5 = new MarkerOptions().position(new LatLng(36.081513,-115.194853)) 
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)) 
          .title("F-2"); 


        mMap.addMarker(marker); 
        mMap.addMarker(marker01); 
        mMap.addMarker(marker02); 
        mMap.addMarker(marker03); 

        mMap.addMarker(marker1); 
        mMap.addMarker(marker2); 
        mMap.addMarker(marker3); 
        mMap.addMarker(marker4); 

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(36.051513,-115.174853), 10.0f)); 

       } 

      } 
     } 

    @Override 
    public boolean onMarkerClick(Marker marker) { 

     /*Toast.makeText(getActivity(), 
        "" + marker.getTitle(), Toast.LENGTH_LONG) 
        .show();*/ 

     marker.showInfoWindow(); 

     return false; 
    } 

    @Override 
    public void onMapClick(LatLng arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onDestroy() { 
     super.onDestroy(); 
    } 

} 

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" 
    tools:context="com.istride.mmps.ContactActivity" > 



    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tableLayout1" 
     android:visibility="gone" 
     android:layout_margin="10dp" > 

     <TextView 
      android:id="@+id/tv_Title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="Bharati Vidyapeeth University's" 
      android:textColor="@color/black_text_color" 
      android:textSize="@dimen/Large_Size" /> 

     <TextView 
      android:id="@+id/tv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_below="@+id/tv_Title" 
      android:text="Department of Information Technology and Management " 
      android:textColor="@color/black_text_color" 
      android:textSize="@dimen/small_size" /> 

     <View 
      android:id="@+id/view2" 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:layout_below="@+id/tv" 
      android:layout_marginTop="10dp" 
      android:background="@color/blue_background" /> 

     <RelativeLayout 
     android:id="@+id/relative" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/view2" 
     android:layout_marginTop="10dp" 
     android:background="@color/gray_home"> 

     <TextView 
      android:id="@+id/textVi1" 
      android:layout_width="90dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/tv_add" 
      android:layout_alignParentTop="true" 
      android:background="@color/blue_background" 
      android:paddingBottom="2dp" 
      android:paddingLeft="8dp" 
      android:paddingRight="13dp" 
      android:paddingTop="2dp" 
      android:gravity="center_vertical" 

      android:text="ADDRESS " 
      android:textColor="@color/white_text_color" 
      android:textSize="@dimen/Medium_size" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/tv_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="10dp" 
      android:layout_toRightOf="@+id/textVi1" 
      android:paddingBottom="2dp" 
      android:paddingTop="2dp" 
      android:text="2nd Floor, Architecture Building, Bharati Vidyapeeth Campus, Dhankawadi, Pune-411043" 
      android:textColor="@color/black_text_color" 
      android:textSize="@dimen/Medium_size" /> 

     </RelativeLayout> 

     <RelativeLayout 
     android:id="@+id/relativeLayout_call" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relative" 
     android:layout_marginTop="10dp" 
     android:background="@color/gray_home"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="90dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/tv_school_office_num" 
      android:layout_alignParentTop="true" 
      android:background="@color/blue_background" 
      android:paddingBottom="2dp" 
      android:paddingLeft="8dp" 
      android:paddingRight="13dp" 
      android:paddingTop="2dp" 
      android:text="PHONE " 
      android:gravity="center_vertical" 
      android:textColor="@color/white_text_color" 
      android:textSize="@dimen/Medium_size" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/tv_school_office_num" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="5dp" 
      android:layout_toRightOf="@+id/textView1" 

      android:layout_toLeftOf="@+id/imageView2" 
      android:textColor="@color/black_text_color" 
       android:paddingTop="2dp" 
       android:textSize="@dimen/Medium_size" 
     android:paddingBottom="2dp" 
      android:text="+91 989898989 asasa asas asasas ass sdsd asas asas ass assas asas ass " /> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="3dp" 
      android:src="@drawable/ic_call" /> 
     </RelativeLayout> 

     <RelativeLayout 
     android:id="@+id/relativeLayout_Email" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relativeLayout_call" 
     android:layout_marginTop="10dp" 
     android:background="@color/gray_home"> 

     <TextView 
      android:id="@+id/tex1" 
      android:layout_width="90dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageView1" 
      android:layout_alignParentTop="true" 
      android:background="@color/blue_background" 
      android:gravity="center_vertical" 
      android:paddingBottom="2dp" 
      android:paddingLeft="8dp" 
      android:paddingRight="13dp" 
      android:paddingTop="2dp" 
      android:text="EMAIL " 
      android:textColor="@color/white_text_color" 
      android:textSize="@dimen/Medium_size" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/tv_school_office_email" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/imageView1" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="10dp" 
      android:gravity="center_vertical" 
      android:layout_toRightOf="@+id/tex1" 
      android:textColor="@color/black_text_color" 
       android:paddingTop="2dp" 
     android:paddingBottom="2dp" 
     android:textSize="@dimen/Medium_size" 
      android:text="[email protected]" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="3dp" 
      android:src="@drawable/ic_email" /> 

     </RelativeLayout> 





    </RelativeLayout> 
<fragment 
      android:id="@+id/map2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 

      android:layout_alignParentRight="true" 

      android:layout_marginTop="10dp" 
      class="com.google.android.gms.maps.SupportMapFragment" 
      android:background="@color/gray_color" 
      android:paddingBottom="5dp" 
      android:layout_above="@+id/footer" 
      android:textSize="@dimen/small_size" /> 

    <RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="10dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" > 


<TextView 
     android:id="@+id/blue" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 

     android:background="#0000FF" 
     android:gravity="center" 
     android:layout_margin="10dp" 

     android:textColor="@color/black_text_color" 
     android:textSize="@dimen/small_size" 
     android:textStyle="bold" /> 

<TextView 
     android:id="@+id/parking" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/blue" 
     android:layout_alignTop="@+id/blue" 
     android:layout_alignBottom="@+id/blue" 
     android:gravity="center_vertical" 
     android:text="Parking" 
     android:textColor="@color/black_text_color" 
     android:textSize="@dimen/Medium_size" 
     android:textStyle="bold" /> 


    <TextView 
     android:id="@+id/cyc" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 

     android:background="#00FFFF" 
     android:gravity="center" 
     android:layout_margin="10dp" 
     android:layout_toRightOf="@+id/parking" 
     android:textColor="@color/black_text_color" 
     android:textSize="@dimen/small_size" 
     android:textStyle="bold" /> 

<TextView 
     android:id="@+id/footer2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/cyc" 
     android:layout_alignTop="@+id/cyc" 
     android:layout_alignBottom="@+id/cyc" 
     android:gravity="center_vertical" 
     android:text="Food" 
     android:textColor="@color/black_text_color" 
     android:textSize="@dimen/Medium_size" 
     android:textStyle="bold" /> 



</RelativeLayout> 
</RelativeLayout> 
1

ich würde Ihnen empfehlen MapView statt SupportFragment zu verwenden verschachtelte Fragment zu vermeiden Details Blick auf die folgenden Posten

beantworten

Should I use MapView or MapFragment

Jetzt ist Ihre ParkFragment

public class MapFragment extends Fragment implements OnMapReadyCallback { 

    private MapView mMapView; 
    private GoogleMap mGoogleMap; 

    public MapFragment() { 
     // Required empty public constructor 
    } 

    public static MapFragment newInstance() { 
     MapFragment fragment = new MapFragment(); 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_map, container, false); 
     mMapView = (MapView) rootView.findViewById(R.id.map); 
     mMapView.onCreate(savedInstanceState); 
     mMapView.getMapAsync(this); 

     return rootView; 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     mMapView.onResume(); 
    } 


    @Override 
    public void onPause() { 
     mMapView.onPause(); 
     super.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     mMapView.onDestroy(); 
     super.onDestroy(); 
    } 


    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     googleMap.getUiSettings().setZoomControlsEnabled(true); 

    } 
} 

fragment_map wie

MapFragment.java aussehen werden.xml

<FrameLayout 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"> 

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

</FrameLayout> 
+0

Ich habe es einfach versucht, und leider hat es das gleiche Problem. – user3746428

1

Das Problem ist, möglicherweise weil es Fragment neu zu erstellen, die den schwarzen Bildschirm verursacht. Wenn Sie mit ViewPager dann können Sie

// Note that you must set adapter before this line otherwise it can cause NullPointerException 
// Or add null check on getAdapter if required 
mViewPager.setOffscreenPageLimit(mViewPager.getAdapter().getCount()); 

verwenden Es ViewPager zwingen wird, nicht Fragmente zweites Mal zu schaffen. Sicher, es benötigt mehr Speicher, aber ich glaube, es ist effizienter, wenn weniger Tabs verwendet werden, also mache ich das normalerweise, um die Wiederherstellung von Fragmenten zu vermeiden.

Zweitens würde ich diese Zeilen von onDestroy entfernen vorschlagen:

SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fullParkMap); 
if (mapFragment != null) { 
    getFragmentManager().beginTransaction().remove(mapFragment).commit(); 
} 

Und dieses Problem zu überwinden, indem onCreateView wie diese Aktualisierung:

private View mView; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    if (mView == null) { 
     mView = inflater.inflate(R.layout.fragment_map, container, false); 
    } 
    return mView; 
} 

Es wird nicht das Layout aufblasen jedes Mal, so dass Sie nicht Gesicht Doppelte ID, Tag Null oder Eltern-ID mit einem anderen Fragment für com.google.android.gms.maps.MapFragment Problem.
Aber stellen Sie sicher, dass Sie passieren falsch in attachToRoot(letzte Argument von inflater.inflate) sonst können Sie erhalten Ausnahmen wie Das angegebene Kind hat bereits ein Elternteil

Letzte, was bei der Verwendung von MapFragment innerhalb Fragment, oder mit anderen Worten, wenn verschachtelte Fragmente verwendet werden, würde ich empfehlen, getChildFragmentManager() anstelle von getFragmentManager() um unerwartete Probleme zu vermeiden.
Denn wie die documentation sagt:
getFragmentManager: die FragmentManager Rück für mit Fragmenten der Interaktion mit diesem Fragment der Aktivität. Beachten Sie, dass dies vor getActivity() während der Zeit, in der das Fragment in eine FragmentTransaction platziert wird, bis es festgeschrieben und an seine Aktivität angefügt ist, etwas ungleich null ist. Wenn dieses Fragment ein Kind eines anderen Fragments ist, wird der hier zurückgegebene FragmentManager getChildFragmentManager() des Elternelements sein.
getChildFragmentManager: Zurückgeben eines privaten FragmentManagers zum Platzieren und Verwalten von Fragmenten innerhalb dieses Fragments.

1

Haben Sie versucht, ein Fragment zu verstecken und anzuzeigen (anstatt es zu entfernen/hinzuzufügen)?

private FragmentA fragmentA; 
private FragmentB fragmentB; 
private FragmentC fragmentC; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    if (savedInstanceState == null) { 
     fragmentA = FragmentA.newInstance("foo"); 
     fragmentB = FragmentB.newInstance("bar"); 
     fragmentC = FragmentC.newInstance("baz"); 
    } 
} 

In Ihrem Fall könnten Sie es in ParkMapFragment usw. ändern

protected void displayFragmentA() { 
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
    if (fragmentA.isAdded()) { // if the fragment is already in container 
     ft.show(fragmentA); 
    } else { // fragment needs to be added to frame container 
     ft.add(R.id.flContainer, fragmentA, "A"); 
    } 
    // Hide fragment B 
    if (fragmentB.isAdded()) { ft.hide(fragmentB); } 
    // Hide fragment C 
    if (fragmentC.isAdded()) { ft.hide(fragmentC); } 
    // Commit changes 
    ft.commit(); 
} 

Quelle: https://github.com/codepath/android_guides/wiki/Creating-and-Using-Fragments

1

Versuchen Sie, diese innerhalb create:

if (v != null) { 
    ViewGroup parent = (ViewGroup) v.getParent(); 
    if (parent != null) 
     parent.removeView(v); 
} 
0

Sie sollten den Übergang von Fragmenten auf diese Weise machen:

Fragment fragment = new YourFragmentToShow(); 
getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, TAG).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); 

Mit TRANSIT_FRAGMENT_FADE Fragment sollte einfach verblassen Rein oder raus; es ist keine starke Navigation damit verbunden, außer dass es aus irgendeinem Grund erscheint oder verschwindet.

es verwenden, wenn Sie das Fragment mit der Karte durch ein anderes Fragment ersetzen, in anderen Fällen empfehle ich die gemeinsame Nutzung, ohne (.setTransition ...):

Fragment fragment = new YourFragmentToShow(); 
getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, TAG).commit(); 
Verwandte Themen