คำถามแรกของคุณที่ทำงานกับเลย์เอาต์ที่รวมโดยใช้ ViewBinding สามารถแก้ไขได้อย่างง่ายดาย
นี่คือตัวอย่างไฟล์main_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view_main"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
</LinearLayout>
และMainFragment.javaสามารถเป็นเช่นนี้
public class MeaningFragment extends Fragment {
    private MainFragmentBinding binding;
    private ToolbarBinding toolbarBinding;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
        binding = MainFragmentBinding.inflate(inflater, container, false);
        toolbarBinding = binding.toolbar;
        return binding.getRoot();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        toolbarBinding = null;
        binding = null;
    }
}
ตอนนี้คุณมีสองการผูกมัด หนึ่งในนั้นคือค่าเริ่มต้นและอีกอันหนึ่งมาจากเค้าโครงที่รวมไว้