我有一个简单的片段:
public class DriverListFragment extends Fragment {
public DriverListFragment() {
}
public static DriverListFragment newInstance(String param1, String param2) {
return new DriverListFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_driver_list, container, false);
}
ListView listViewDriver;
DriverListAdapter adapter;
RoomWithRxJavaViewModel viewModel;
FloatingActionButton btnOpenDriverAddFragment2;
CustomLinearLayout customLinearLayout;
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
listViewDriver = view.findViewById(R.id.listAllDrivers);
viewModel = new RoomWithRxJavaViewModel(getActivity().getApplication());
btnOpenDriverAddFragment2 = view.findViewById(R.id.btnOpenDriverAddFragment2);
customLinearLayout = (CustomLinearLayout) view.findViewById(R.id.cusLL);
Snackbar.make(customLinearLayout, "Text to display", Snackbar.LENGTH_LONG).show();
}
}
我从我的主要活动中调用:
final DriverListFragment fragment = new DriverListFragment();
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.frameLHaupt, fragment, "FragmentHaupt");
transaction.disallowAddToBackStack(); //main fragment, so no popbackstack
transaction.commit();
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior=".pkgActivity.MoveUpwardBehaviour"
tools:context=".pkgTestforend.DriverListFragment">
<ListView
android:id="@+id/listAllDrivers"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
<com.example.dochjavatestimplementation.pkgTestforend.CustomLinearLayout
android:layout_width="match_parent"
android:id="@+id/cusLL"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnOpenDriverAddFragment2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_person_add_24"
/>
</RelativeLayout>
</com.example.dochjavatestimplementation.pkgTestforend.CustomLinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
问题是我的小吃店会弹出我的 customlinearlayout 几秒钟,如果我在按钮/linearlayout 仍然向上时旋转手机,按钮仍然可见,尽管它应该被销毁,因为 oncreate 再次被调用?
当我旋转手机时:
旋转手机时不应该破坏按钮状态的原因是什么?