-1

我正在使用导航抽屉。我有片段要导航。其中之一包括谷歌地图。带有 Google Map 的片段在第一次被调用时打开(在 onCreate 方法中)。但随后我导航到另一个片段,然后当我尝试使用 Google 地图导航回片段(使用 onNavigationItemSelected 方法)时,它没有显示出来。另一个片段继续停留。我正在使用 android.support.v4.app.Fragment。

4

1 回答 1

0

可能您正在将片段添加到另一个上,但您应该替换以使它们出现:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, new YourFragment());
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();
于 2019-05-04T18:10:36.710 回答