public class DYLinearLayout extends LinearLayoutManager { PagerSnapHelper helper; public DYLinearLayout(Context context) { super(context); } @Override public void onAttachedToWindow(RecyclerView view) { super.onAttachedToWindow(view); helper = new PagerSnapHelper(); helper.attachToRecyclerView(view); } }
public class RecommenFragment extends BaseFragment<FragmentRecommenBinding, VideoViewModel> {
@Override public void initview() { DYLinearLayout layout = new DYLinearLayout(getContext()); fragment.cyc.setLayoutManager(layout); fragment.cyc.setAdapter(va); fragment.cyc.setOnScrollChangeListener(new View.OnScrollChangeListener() { @Override public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { int firstVisibleItemPosition = layout.findFirstVisibleItemPosition(); StandardGSYVideoPlayer player = (StandardGSYVideoPlayer) va.getViewByPosition(firstVisibleItemPosition,R.id.gsy); player.startPlayLogic(); } }); }
}