【发布时间】:2019-07-30 11:18:23
【问题描述】:
当我点击第一个片段的 FAB 时,我在主活动中有 2 个 片段,它将被第二个片段替换,当我在片段 2 中按下返回按钮时,它将返回片段 1,但它不显示布局的很大一部分,请查看此图像以了解问题:
2: when I pressed back button in 2nd fragment and cames back to 1st fragment
在第一个片段 xml 中,我有 3 部分主要项目:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.google.android.material.appbar.AppBarLayout>
...
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView>
...
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton/>
</androidx.coordinatorlayout.widget.CoordinatorLayout >
实际上,当我从第二个片段返回到第一个片段时,NestedScrollview 及其子项不显示。
在 Fragment 1st 中,我使用以下代码开始 Fragment 2nd:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_first, container, false);
FloatingActionButton fab = view.findViewById(R.id.fabAddWord);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getFragmentManager()
.beginTransaction()
.addToBackStack(TAG)
.replace(R.id.fragment_container, SecondFragment.newInstance(),
WordSearchFragment.class.getSimpleName())
.commit();
}
});
return view;
}
【问题讨论】: