簡體   English   中英

被破壞片段的按鈕仍然可見

[英]Button of destroyed fragment still visible

我有一個簡單的片段:

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 再次被調用?

默認狀態

當我旋轉手機時:

旋轉支架

旋轉手機時不應該損壞按鈕 state 的原因是什么?

替換transaction.add(R.id.frameLHaupt, fragment, "FragmentHaupt"); with transaction.replace(R.id.frameLHaupt, fragment, "FragmentHaupt");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM