1.重写布局管理类
public class MyLinearManager extends LinearLayoutManager {
PagerSnapHelper mPagerSnapHelper;
public MyLinearManager(Context context) {
super(context);
}
public MyLinearManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public MyLinearManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onAttachedToWindow(RecyclerView view) {
super.onAttachedToWindow(view);
mPagerSnapHelper = new PagerSnapHelper();
mPagerSnapHelper.attachToRecyclerView(view);
}
}
2.展示视频的RecycleView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".mvp.view.fragment.EightFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_eight"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
3.java
//获取控件
//RecycleView
private RecyclerView rvEight;
//视频适配器
private MyVideoAdapter mMyVideoAdapter;
//布局管理类
private MyLinearManager mMyLinearManager;
//视频集合 这里是我自己解的串
private ArrayList<VideoBean.DataBean> mList = new ArrayList<>();
//适配
mMyLinearManager = new MyLinearManager(getActivity());
rvEight.setLayoutManager(mMyLinearManager);
rvEight.setAdapter(mMyVideoAdapter);
绑定视频item
??
整个项目由MVP完成?
?
|