Просмотр исходного кода

增加首页曲目列表滚动模式

Pq 1 год назад
Родитель
Сommit
2d166acfe4

+ 8 - 0
student/src/main/java/com/cooleshow/student/ui/main/NewHomeFragment.java

@@ -80,6 +80,8 @@ import androidx.core.widget.NestedScrollView;
 import androidx.fragment.app.Fragment;
 import androidx.recyclerview.widget.GridLayoutManager;
 import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.LinearSnapHelper;
+import androidx.recyclerview.widget.PagerSnapHelper;
 import androidx.viewpager.widget.ViewPager;
 import androidx.viewpager2.widget.ViewPager2;
 
@@ -168,6 +170,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager recommendMusicSheetManager = new LinearLayoutManager(getContext());
         recommendMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mRecommendAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper recommendlinearSnapHelper =new LinearSnapHelper();
+        recommendlinearSnapHelper.attachToRecyclerView(mViewBinding.rvRecommendTrack);
         HomeHotMusicSheetItemDecoration itemDecoration1 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvRecommendTrack.addItemDecoration(itemDecoration1);
         mViewBinding.rvRecommendTrack.setLayoutManager(recommendMusicSheetManager);
@@ -177,6 +181,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager latestMusicSheetManager = new LinearLayoutManager(getContext());
         latestMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mLatestAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper linearSnapHelper =new LinearSnapHelper();
+        linearSnapHelper.attachToRecyclerView(mViewBinding.rvLatestTrack);
         HomeHotMusicSheetItemDecoration itemDecoration2 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvLatestTrack.addItemDecoration(itemDecoration2);
         mViewBinding.rvLatestTrack.setLayoutManager(latestMusicSheetManager);
@@ -187,6 +193,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager musicSheetManager = new LinearLayoutManager(getContext());
         musicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mHomeHotMusicSheetAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper hotTracklinearSnapHelper =new LinearSnapHelper();
+        hotTracklinearSnapHelper.attachToRecyclerView(mViewBinding.rvHotTrack);
         HomeHotMusicSheetItemDecoration itemDecoration = new HomeHotMusicSheetItemDecoration(0, 0, 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvHotTrack.addItemDecoration(itemDecoration);
         mViewBinding.rvHotTrack.setLayoutManager(musicSheetManager);

+ 7 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/main/NewHomeFragment.java

@@ -77,6 +77,7 @@ import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentActivity;
 import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.LinearSnapHelper;
 import androidx.viewpager.widget.ViewPager;
 
 /**
@@ -129,6 +130,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager recommendMusicSheetManager = new LinearLayoutManager(getContext());
         recommendMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mRecommendAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper recommendSnapHelper =new LinearSnapHelper();
+        recommendSnapHelper.attachToRecyclerView(mViewBinding.rvRecommendTrack);
         HomeHotMusicSheetItemDecoration itemDecoration1 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvRecommendTrack.addItemDecoration(itemDecoration1);
         mViewBinding.rvRecommendTrack.setLayoutManager(recommendMusicSheetManager);
@@ -138,6 +141,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager latestMusicSheetManager = new LinearLayoutManager(getContext());
         latestMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mLatestAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper latestTrackSnapHelper =new LinearSnapHelper();
+        latestTrackSnapHelper.attachToRecyclerView(mViewBinding.rvLatestTrack);
         HomeHotMusicSheetItemDecoration itemDecoration2 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvLatestTrack.addItemDecoration(itemDecoration2);
         mViewBinding.rvLatestTrack.setLayoutManager(latestMusicSheetManager);
@@ -147,6 +152,8 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         LinearLayoutManager musicSheetManager = new LinearLayoutManager(getContext());
         musicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mHomeHotMusicSheetAdapter = new HomeHotMusicSheetAdapter();
+        LinearSnapHelper hotTrackSnapHelper =new LinearSnapHelper();
+        hotTrackSnapHelper.attachToRecyclerView(mViewBinding.rvHotTrack);
         HomeHotMusicSheetItemDecoration itemDecoration = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
         mViewBinding.rvHotTrack.addItemDecoration(itemDecoration);
         mViewBinding.rvHotTrack.setLayoutManager(musicSheetManager);