content: package com.example.vibemusicplayer.ui.fragment;
  
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.fragment.app.Fragment;
  import androidx.viewpager2.widget.ViewPager2;
  
  import com.example.vibemusicplayer.R;
  import com.example.vibemusicplayer.ui.adapter.HomeAdapter;
  import com.google.android.material.tabs.TabLayout;
  import com.google.android.material.tabs.TabLayoutMediator;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class HomeFragment extends Fragment {
  
      private ViewPager2 viewPager2;
      private TabLayout tabLayout;
      List<String> titles = new ArrayList<>();
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_home, container, false);
          viewPager2 = view.findViewById(R.id.viewpager);
          tabLayout = view.findViewById(R.id.sliding_tabs);
  
          // 添加标题
          titles.add("曲库");
          titles.add("专辑");
          titles.add("歌手");
          titles.add("喜欢");
  
          // 实例化适配器
          HomeAdapter homeAdapter = new HomeAdapter(this);
          viewPager2.setAdapter(homeAdapter);
  
          new TabLayoutMediator(tabLayout, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
              @Override
              public void onConfigureTab(@NonNull TabLayout.Tab tab, int i) {
                  tab.setText(titles.get(i));
              }
          }).attach();
  
          return view;
      }
  
      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
      }
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
      }
  }