APP下载地址
效果图:
实现要求:
1. 项目框架:MVP;注意:最大程度上避免内存泄漏;
2. 图片加载:Fresco框架;
3.网络加载框架:使用Retrofit+RxJava+okHttp实现网络加载;
4. 数据展示使用RecylerView;
5. ButterKnife,EventBus
业务逻辑需求:
1. 使用Mvp+Retrofit+RxJava+okHttp完成框架搭建
2. 实现如图效果,精选页面 banner展示,精选推荐,点击跳转到电影详情页面,并可以直接播放影片,titlebar部
分采用沉浸式状态栏
3. 详情页面实现简介评论功能;
4. 点击影片可进行播放,全屏。
添加依赖:
compile 'com.android.support:design:26.0.0-alpha1' compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'io.reactivex.rxjava2:rxjava:2.1.7' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' compile 'com.jpeng:JPTabBar:1.1.4' compile 'com.youth.banner:banner:1.4.9' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.facebook.fresco:fresco:0.12.0' testCompile 'junit:junit:4.12' compile project(':superplayerlibrary') compile 'org.greenrobot:eventbus:3.1.1'//enentbus compile 'com.jcodecraeer:xrecyclerview:1.3.2'封装MVP:
http:
ApiService
public interface ApiService { @GET("homePageApi/homePage.do") Flowable<HomePage> getHome(); @GET("videoDetailApi/videoDetail.do") Flowable<VideoDetail> getDetail(@QueryMap Map<String,String> map); @GET("Commentary/getCommentList.do") Flowable<CommentList> getComment(@QueryMap Map<String,String> map); }RetrofitUtils
public class RetrofitUtils { private static volatile RetrofitUtils instance; private ApiService apiService; private RetrofitUtils(){ OkHttpClient client = new OkHttpClient(); Retrofit retrofit = new Retrofit.Builder() .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("http://api.svipmovie.com/front/") .build(); apiService = retrofit.create(ApiService.class); } public static RetrofitUtils getInstance(){ if (null==instance){ synchronized (RetrofitUtils.class){ if (instance==null){ instance = new RetrofitUtils(); } } } return instance; } public ApiService getApiService(){ return apiService; } }model层
HomeModel
public class HomeModel implements IModel{ private HomePresenter presenter; public HomeModel(HomePresenter presenter) { this.presenter = presenter; } @Override public void getData(Map<String, String> map) { Flowable<VideoDetail> detail = RetrofitUtils.getInstance().getApiService().getDetail(map); presenter.getDetail(detail); } @Override public void getData() { Flowable<HomePage> flowable = RetrofitUtils.getInstance().getApiService().getHome(); presenter.getNews(flowable); } @Override public void getCome(Map<String, String> map) { Flowable<CommentList> comment = RetrofitUtils.getInstance().getApiService().getComment(map); presenter.getComment(comment); } }IModel
public interface IModel { void getData(Map<String,String> map); void getData(); void getCome(Map<String,String> map); }presenter层
BasePresenter
public interface BasePresenter { void getData(Map<String,String> map); void getData(); void getCome(Map<String,String> map); }HomePresenter
public class HomePresenter implements BasePresenter { private DisposableSubscriber subscriber1; private DisposableSubscriber subscriber2; @Override public void getData() { HomeModel model = new HomeModel(this); model.getData(); } @Override public void getCome(Map<String, String> map) { HomeModel model = new HomeModel(this); model.getCome(map); } private IView iv; private DisposableSubscriber subscriber; public void attachView(IView iv) { this.iv = iv; } public void detachView() { if (iv != null) { iv = null; } if (!subscriber.isDisposed()) { subscriber.dispose(); } if (!subscriber1.isDisposed()){ subscriber1.dispose(); } if (!subscriber2.isDisposed()){ subscriber2.dispose(); } } @Override public void getData(Map<String, String> map) { HomeModel model = new HomeModel(this); model.getData(map); } public void getNews(Flowable<HomePage> flowable) { subscriber = flowable.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSubscriber<HomePage>() { @Override public void onNext(HomePage homePage) { if (homePage != null) { iv.onSuccess(homePage); } } @Override public void onError(Throwable t) { iv.onFailed((Exception) t); } @Override public void onComplete() { } }); } public void getDetail(Flowable<VideoDetail> flowable) { subscriber1 = flowable.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSubscriber<VideoDetail>() { @Override public void onNext(VideoDetail videoDetail) { if (videoDetail != null) { iv.onSuccess(videoDetail); } } @Override public void onError(Throwable t) { iv.onFailed((Exception) t); } @Override public void onComplete() { } }); } public void getComment(Flowable<CommentList> flowable){ subscriber2 = flowable.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSubscriber<CommentList>() { @Override public void onNext(CommentList commentList) { if (commentList!=null){ iv.onSuccess(commentList); } } @Override public void onError(Throwable t) { iv.onFailed((Exception) t); } @Override public void onComplete() { } }); } }view层
public interface IView { void onSuccess(Object o); void onFailed(Exception e); }沉浸式封装:
ImmersionUtils
public class ImmersionUtils { public void setImmersion(Window window, ActionBar supprotActionBar) { if(window != null) { if(Build.VERSION.SDK_INT >= 21) { View decorView = window.getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); window.setStatusBarColor(Color.TRANSPARENT); } } if(supprotActionBar != null) { ActionBar actionBar = supprotActionBar; actionBar.hide(); } } }自定义二级列表:
MyExListView
public class MyExListView extends ExpandableListView { public MyExListView(Context context) { this(context, null); } public MyExListView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyExListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }自定义RecyclerView
MyRecyclerView
public class MyRecyclerView extends RecyclerView{ public MyRecyclerView(Context context) { super(context); } public MyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public MyRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, measureSpec); } }自定义scorllView
MyScrollView
public class MyScrollView extends ScrollView { private OnScrollListener listener; public void setOnScrollListener(OnScrollListener listener) { this.listener = listener; } public MyScrollView(Context context) { super(context); } public MyScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public interface OnScrollListener{ void onScroll(int scrollY); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if(listener != null){ listener.onScroll(t); } } }
MainActivity
public class MainActivity extends AppCompatActivity { private FragmentManager manager; private List<Fragment> list; @Titles private static final String[] mTitles = {"精选","专题","发现","我的"}; @SeleIcons private static final int[] mSeleIcons = {R.mipmap.found_select,R.mipmap.special_select,R.mipmap.fancy_select,R.mipmap.my_select}; @NorIcons private static final int[] mNormalIcons = {R.mipmap.found, R.mipmap.special, R.mipmap.fancy, R.mipmap.my}; private ViewPager vp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImmersionUtils immersionUtils = new ImmersionUtils(); immersionUtils.setImmersion(getWindow(),getSupportActionBar()); JPTabBar tabBar = (JPTabBar) findViewById(R.id.tabbar); vp = (ViewPager) findViewById(R.id.vp); tabBar.setBackgroundResource(R.mipmap.bottom_bg); list = new ArrayList<>(); list.add(new FragmentFound()); list.add(new FragmentSpecial()); list.add(new FragmentFancy()); list.add(new FragmentMy()); MyPager pager = new MyPager(getSupportFragmentManager(),list); vp.setAdapter(pager); tabBar.setContainer(vp); } class MyPager extends FragmentPagerAdapter { private List<Fragment> list; public MyPager(FragmentManager fm, List<Fragment> list) { super(fm); this.list=list; } @Override public Fragment getItem(int position) { return list.get(position); } @Override public int getCount() { return list.size(); } } }VideoActivity
public class VideoActivity extends AppCompatActivity implements IView, SuperPlayer.OnNetChangeListener{ private HomePresenter presenter; private ImageView back; private TextView title; private TabLayout tabLayout; private ViewPager vp; private SuperPlayer superPlayer; private String hdurl; private String video_title; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); EventBus.getDefault().register(this); ImmersionUtils immersionUtils = new ImmersionUtils(); immersionUtils.setImmersion(getWindow(),getSupportActionBar()); intiView(); String id = getIntent().getStringExtra("id"); EventBus.getDefault().post(id); Map<String, String> map = new HashMap<>(); map.put("mediaId",id); presenter = new HomePresenter(); presenter.getData(map); presenter.attachView(this); } public void intiView(){ superPlayer = (SuperPlayer) findViewById(R.id.view_super_player); tabLayout = (TabLayout) findViewById(R.id.tab_layout); back = (ImageView) findViewById(R.id.back); title = (TextView) findViewById(R.id.title); vp = (ViewPager) findViewById(R.id.vp); final List<Fragment> fragmentList = new ArrayList<>(); fragmentList.add(new FragmentSynopsis()); fragmentList.add(new FragmentComment()); vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return fragmentList.get(position); } @Override public int getCount() { return fragmentList.size(); } }); tabLayout.setupWithViewPager(vp); tabLayout.getTabAt(0).setText("简介"); tabLayout.getTabAt(1).setText("评论"); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); overridePendingTransition(R.anim.showlefttoright,R.anim.hidelefttoright); } }); } /** * 初始化播放器 */ private void initPlayer(){ // if(isLive){ // player.setLive(true);//设置该地址是直播的地址 // } superPlayer.setNetChangeListener(true)//设置监听手机网络的变化 .setOnNetChangeListener(this)//实现网络变化的回调 .onPrepared(new SuperPlayer.OnPreparedListener() { @Override public void onPrepared() { /** * 监听视频是否已经准备完成开始播放。(可以在这里处理视频封面的显示跟隐藏) */ } }).onComplete(new Runnable() { @Override public void run() { /** * 监听视频是否已经播放完成了。(可以在这里处理视频播放完成进行的操作) */ } }).onInfo(new SuperPlayer.OnInfoListener() { @Override public void onInfo(int what, int extra) { /** * 监听视频的相关信息。 */ } }).onError(new SuperPlayer.OnErrorListener() { @Override public void onError(int what, int extra) { /** * 监听视频播放失败的回调 */ } }).setTitle(video_title)//设置视频的titleName .play(hdurl);//开始播放视频 superPlayer.setScaleType(SuperPlayer.SCALETYPE_FITXY); superPlayer.setPlayerWH(0,superPlayer.getMeasuredHeight());//设置竖屏的时候屏幕的高度,如果不设置会切换后按照16:9的高度重置 } @Override public void onSuccess(Object o) { if (o!=null){ VideoDetail videoDetail = (VideoDetail) o; video_title = videoDetail.getRet().getTitle(); this.title.setText(video_title); hdurl = videoDetail.getRet().getHDURL(); EventBus.getDefault().post(videoDetail); initPlayer(); } } @Override public void onFailed(Exception e) { } /** * 下面的这几个Activity的生命状态很重要 */ @Override protected void onPause() { super.onPause(); if (superPlayer != null) { superPlayer.onPause(); } } @Override protected void onResume() { super.onResume(); if (superPlayer != null) { superPlayer.onResume(); } } @Override protected void onDestroy() { super.onDestroy(); if (superPlayer != null) { superPlayer.onDestroy(); } EventBus.getDefault().unregister(this); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (superPlayer != null) { superPlayer.onConfigurationChanged(newConfig); } } @Override public void onBackPressed() { if (superPlayer != null && superPlayer.onBackPressed()) { return; } super.onBackPressed(); } @Subscribe public void onMessageEvent(MessageID event){ String idd = event.getId(); Log.i("bbbb", "onMessageEvent: "+idd); Map<String, String> map = new HashMap<>(); map.put("mediaId",idd); presenter.getData(map); presenter.attachView(new IView() { @Override public void onSuccess(Object o) { VideoDetail videoDetail = (VideoDetail) o; video_title = videoDetail.getRet().getTitle(); title.setText(video_title); hdurl = videoDetail.getRet().getHDURL(); EventBus.getDefault().post(videoDetail); initPlayer(); } @Override public void onFailed(Exception e) { } }); } /** * 网络链接监听类 */ @Override public void onWifi() { Toast.makeText(this,"当前网络环境是WIFI",Toast.LENGTH_SHORT).show(); } @Override public void onMobile() { Toast.makeText(this,"当前网络环境是手机网络",Toast.LENGTH_SHORT).show(); } @Override public void onDisConnect() { Toast.makeText(this,"网络链接断开",Toast.LENGTH_SHORT).show(); } @Override public void onNoAvailable() { Toast.makeText(this,"无网络链接",Toast.LENGTH_SHORT).show(); } }FragmentFound
public class FragmentFound extends Fragment implements IView { private HomePresenter presenter; private List<HomePage.RetBean.ListBean.ChildListBean> list = new ArrayList<>(); private Banner banner; private EditText et_sousuo; private List<String> imgList = new ArrayList<>(); private List<String> idList = new ArrayList<>(); private RecyclerView recy_view; private HomeAdapter adapter; private MyScrollView scroll; private RelativeLayout header; private MyExListView elv; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = View.inflate(getContext(), R.layout.fragmentfound, null); initView(view); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); presenter = new HomePresenter(); presenter.getData(); presenter.attachView(this); // LinearLayoutManager manager = new LinearLayoutManager(getContext()); // recy_view.setLayoutManager(manager); // adapter = new HomeAdapter(getContext(), list); // recy_view.setAdapter(adapter); scroll.setOnScrollListener(new MyScrollView.OnScrollListener() { @Override public void onScroll(int scrollY) { int i = dip2px(getActivity(), scrollY); int dp = px2dip(getActivity(), i); if (dp>500){ header.setVisibility(View.VISIBLE); }else { header.setVisibility(View.GONE); } } }); } public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } public void initView(View view) { banner = view.findViewById(R.id.ban); scroll = view.findViewById(R.id.scroll); et_sousuo = view.findViewById(R.id.et_sousuo); recy_view = view.findViewById(R.id.recy_view); header = view.findViewById(R.id.header); elv = view.findViewById(R.id.elv); } @Override public void onSuccess(Object o) { if (o != null) { HomePage homePage = (HomePage) o; imgList.clear(); idList.clear(); final List<HomePage.RetBean.ListBean> listBeen = homePage.getRet().getList(); List<HomePage.RetBean.ListBean.ChildListBean> childList = listBeen.get(0).getChildList(); for (int i = 0; i < childList.size(); i++) { imgList.add(childList.get(i).getPic()); idList.add(childList.get(i).getDataId()); } listBeen.remove(0); listBeen.remove(2); HomeExpandAdapter adapter = new HomeExpandAdapter(getContext(), listBeen); elv.setAdapter(adapter); elv.setGroupIndicator(null); for (int i=0;i<listBeen.size();i++){ elv.expandGroup(i); } elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) { Intent intent = new Intent(getContext(), VideoActivity.class); intent.putExtra("id",listBeen.get(i).getChildList().get(i1).getDataId()); startActivity(intent); getActivity().overridePendingTransition(R.anim.showrighttoleft,R.anim.hiderighttoleft); return false; } }); Log.i("zzz", "onSuccess: " + list.size()); banner.setImageLoader(new ImgApp());//引用ImgApp,加载里面的东西 banner.setImages(imgList); banner.isAutoPlay(true); banner.setDelayTime(2000); banner.start(); banner.setOnBannerListener(new OnBannerListener() { @Override public void OnBannerClick(int position) { Intent intent = new Intent(getContext(), VideoActivity.class); intent.putExtra("id",idList.get(position)); startActivity(intent); getActivity().overridePendingTransition(R.anim.showrighttoleft,R.anim.hiderighttoleft); } }); } } @Override public void onFailed(Exception e) { } }FragmentComment
public class FragmentComment extends Fragment { private XRecyclerView xRecyclerView; private int count = 1; private int id; private List<CommentList.RetBean.ListBean> list = new ArrayList<>(); private MyAdapter adapter; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = View.inflate(getContext(), R.layout.fragmentcoment, null); xRecyclerView = (XRecyclerView) view.findViewById(R.id.xrecyclerView); return view; } @Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Subscribe public void onMessageEvent(MessageEvent event) { id = event.getId(); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); xRecyclerView.setLayoutManager(layoutManager); getData(count); xRecyclerView.setPullRefreshEnabled(true); xRecyclerView.setLoadingMoreEnabled(true); xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman); xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { @Override public void onRefresh() { new Handler().postDelayed(new Runnable(){ public void run() { count=1; getData(count); xRecyclerView.refreshComplete(); } }, 2000); } @Override public void onLoadMore() { new Handler().postDelayed(new Runnable(){ public void run() { count++; getData(count); xRecyclerView.refreshComplete(); } }, 2000); } }); } public void getData(int num) { Map<String, String> map = new HashMap<>(); map.put("mediaId", id + ""); map.put("pnum", num + ""); HomePresenter presenter = new HomePresenter(); presenter.getCome(map); presenter.attachView(new IView() { @Override public void onSuccess(Object o) { if (o != null) { CommentList commentList = (CommentList) o; Log.i("aaa", "onSuccess: "+commentList.getMsg()); list.clear(); list.addAll(commentList.getRet().getList()); adapter = new MyAdapter(list, getContext()); xRecyclerView.setAdapter(adapter); } } @Override public void onFailed(Exception e) { } }); } @Override public void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); } }FragmentSynopsis
public class FragmentSynopsis extends Fragment{ private TextView synopsis; private RecyclerView recy_view; private SynopsisAdapter adapter; private TextView like; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = View.inflate(getContext(), R.layout.synopsis_item, null); initView(view); return view; } private void initView(View view) { synopsis = view.findViewById(R.id.synopsis); recy_view = view.findViewById(R.id.recy_view); like = view.findViewById(R.id.you_like); } @Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @Subscribe public void MessageEvent(VideoDetail detail){ synopsis.setText(detail.getRet().getDescription()); final List<VideoDetail.RetBean.ListBean> list = detail.getRet().getList(); final List<VideoDetail.RetBean.ListBean.ChildListBean> childList = list.get(0).getChildList(); like.setText(list.get(0).getTitle()); GridLayoutManager manager = new GridLayoutManager(getContext(), 3); recy_view.setLayoutManager(manager); adapter = new SynopsisAdapter(getContext(), childList); recy_view.setAdapter(adapter); adapter.setOnItemClickListener(new SynopsisAdapter.OnItemClickListener() { @Override public void onClick(int position) { String dataId = childList.get(position).getDataId(); MessageID messageID = new MessageID(dataId); EventBus.getDefault().post(messageID); Log.i("aaaa", "onClick: "+dataId); } @Override public void onLongClick(int position) { } }); } @Override public void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); } }适配器:
HomeExpandAdapter
public class HomeExpandAdapter extends BaseExpandableListAdapter { private Context context; private List<HomePage.RetBean.ListBean> listBeen; public HomeExpandAdapter(Context context, List<HomePage.RetBean.ListBean> listBeen) { this.context = context; this.listBeen = listBeen; } @Override public int getGroupCount() { return listBeen.size(); } @Override public int getChildrenCount(int i) { return listBeen.get(i).getChildList().size(); } @Override public Object getGroup(int i) { return listBeen.get(i); } @Override public Object getChild(int i, int i1) { return listBeen.get(i).getChildList().get(i1); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { GroupHolder holder = null; if (view == null) { holder = new GroupHolder(); view = View.inflate(context, R.layout.group_item, null); holder.group_title = view.findViewById(R.id.group_title); view.setTag(holder); } holder = (GroupHolder) view.getTag(); holder.group_title.setText(listBeen.get(i).getTitle()); return view; } @Override public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { ChildHolder holder = null; if (view == null) { holder = new ChildHolder(); view = View.inflate(context, R.layout.found_item, null); holder.child_img = view.findViewById(R.id.item_img); holder.child_title = view.findViewById(R.id.item_title); view.setTag(holder); } holder = (ChildHolder) view.getTag(); holder.child_title.setText(listBeen.get(i).getChildList().get(i1).getTitle()); holder.child_img.setImageURI(listBeen.get(i).getChildList().get(i1).getPic()); return view; } @Override public boolean isChildSelectable(int i, int i1) { return true; } class GroupHolder { TextView group_title; } class ChildHolder { TextView child_title; SimpleDraweeView child_img; } }MyAdapter
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<CommentList.RetBean.ListBean> list; private Context context; public MyAdapter(List<CommentList.RetBean.ListBean> list, Context context) { this.list = list; this.context = context; } //创建新View,被LayoutManager所调用 @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View view = View.inflate(context, R.layout.comment_item, null); ViewHolder vh = new ViewHolder(view); return vh; } //将数据与界面进行绑定的操作 @Override public void onBindViewHolder(ViewHolder viewHolder, int position) { viewHolder.item_img.setImageURI(list.get(position).getUserPic()); viewHolder.title.setText(list.get(position).getPhoneNumber()); viewHolder.time.setText(list.get(position).getTime()); viewHolder.msg.setText(list.get(position).getMsg()); } //获取数据的数量 @Override public int getItemCount() { return list.size(); } //自定义的ViewHolder,持有每个Item的的所有界面元素 public static class ViewHolder extends RecyclerView.ViewHolder { private TextView title; private TextView time; private TextView msg; private SimpleDraweeView item_img; public ViewHolder(View view) { super(view); title = (TextView) view.findViewById(R.id.coom_title); time = (TextView) view.findViewById(R.id.coom_time); msg = (TextView) view.findViewById(R.id.coom_msg); item_img = view.findViewById(R.id.item_img); } } }SynopsisAdapter
public class SynopsisAdapter extends RecyclerView.Adapter<SynopsisAdapter.ViewHolder>{ private Context context; private List<VideoDetail.RetBean.ListBean.ChildListBean> list; public SynopsisAdapter(Context context, List<VideoDetail.RetBean.ListBean.ChildListBean> list) { this.context = context; this.list = list; } private OnItemClickListener mOnItemClickListener; public interface OnItemClickListener{ void onClick(int position); void onLongClick(int position); } public void setOnItemClickListener(OnItemClickListener onItemClickListener ){ this. mOnItemClickListener=onItemClickListener; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.found_item, null); ViewHolder holder = new ViewHolder(view); return holder; } @Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.item_img.setImageURI(list.get(position).getPic()); holder.item_title.setText(list.get(position).getTitle()); if( mOnItemClickListener!= null){ holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mOnItemClickListener.onClick(position); } }); holder. itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { mOnItemClickListener.onLongClick(position); return false; } }); } } @Override public int getItemCount() { return list.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ private final SimpleDraweeView item_img; private final TextView item_title; public ViewHolder(View itemView) { super(itemView); item_img = itemView.findViewById(R.id.item_img); item_title = itemView.findViewById(R.id.item_title); } } }布局文件:
anim页面左进右出动画效果
hidelefttoright.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0%p" android:toXDelta="100%p" android:duration="500" /> </set>hiderighttoleft.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0%p" android:toXDelta="-100%p" android:duration="500" /> </set>showlefttoright.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%p" android:toXDelta="0%p" android:duration="500" /> </set>showrighttoleft.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.com.videodemo.MainActivity"> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="match_parent" > </android.support.v4.view.ViewPager> <com.jpeng.jptabbar.JPTabBar android:id="@+id/tabbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:TabHeight="50dp" app:TabAnimate="None" android:layout_alignParentBottom="true" /> </RelativeLayout>activity_video.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/found_shap" android:orientation="vertical" tools:context="com.bwie.com.videodemo.VideoActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#1488e1"> <ImageView android:id="@+id/back" android:layout_width="30dp" android:layout_height="30dp" android:layout_centerVertical="true" android:src="@mipmap/back" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="我是标题" android:textColor="#fff" android:textSize="20sp" /> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:src="@mipmap/collection" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="250dp"> <com.superplayer.library.SuperPlayer android:id="@+id/view_super_player" android:layout_width="match_parent" android:layout_height="match_parent"></com.superplayer.library.SuperPlayer> </RelativeLayout> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="center_horizontal" app:tabBackground="@color/colortab" app:tabGravity="center" app:tabIndicatorColor="#158424" app:tabIndicatorHeight="3dp" app:tabMode="scrollable" app:tabSelectedTextColor="#158424" app:tabTextAppearance="@android:style/TextAppearance.Holo.Large" app:tabTextColor="#fff"></android.support.design.widget.TabLayout> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v4.view.ViewPager> </LinearLayout>comment_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="140dp" android:orientation="horizontal" > <com.facebook.drawee.view.SimpleDraweeView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/item_img" android:layout_gravity="center" android:layout_centerHorizontal="true" fresco:placeholderImage="@mipmap/user" fresco:roundAsCircle="true" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginLeft="10dp" > <TextView android:id="@+id/coom_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名" android:textStyle="bold" android:textSize="18sp" android:textColor="#fff" android:layout_margin="7dp" /> <TextView android:id="@+id/coom_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="日期" android:textSize="18sp" android:textColor="#fff" android:layout_margin="7dp" /> <TextView android:id="@+id/coom_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="评论" android:textColor="#ddd" android:textSize="18sp" android:layout_margin="7dp" /> </LinearLayout> </LinearLayout> </LinearLayout>found_item.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/item_img" android:layout_width="match_parent" android:layout_height="250dp" android:layout_centerHorizontal="true" fresco:roundingBorderWidth="8dp" fresco:roundingBorderColor="#1f6a88" /> <TextView android:id="@+id/item_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textColor="#fff" android:text="我是标题" android:layout_margin="5dp" android:layout_below="@+id/item_img" android:layout_centerHorizontal="true" /> </RelativeLayout>fragmentcoment.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.jcodecraeer.xrecyclerview.XRecyclerView android:id="@+id/xrecyclerView" android:layout_width="match_parent" android:layout_height="match_parent"></com.jcodecraeer.xrecyclerview.XRecyclerView> </LinearLayout>fragmentfound.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/found_shap" android:orientation="vertical"> <com.bwie.com.videodemo.view.MyScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.youth.banner.Banner android:id="@+id/ban" android:layout_width="match_parent" android:layout_height="250dp"></com.youth.banner.Banner> <com.bwie.com.videodemo.view.MyExListView android:id="@+id/elv" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <EditText android:id="@+id/et_sousuo" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="100dp" android:layout_marginRight="100dp" android:layout_marginTop="15dp" android:background="@drawable/edittext_shap" android:drawableLeft="@mipmap/search" android:hint="一念天堂" android:paddingLeft="10dp" android:textColorHint="#fff" /> <RelativeLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="50dp" android:visibility="gone" android:background="#3f9be2"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="精选" android:textColor="#fff" android:textSize="25sp" /> </RelativeLayout> </RelativeLayout> </com.bwie.com.videodemo.view.MyScrollView> </RelativeLayout>group_item.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"> <RelativeLayout android:id="@+id/rel" android:layout_width="match_parent" android:layout_height="40dp" android:layout_below="@+id/ban" android:layout_margin="5dp"> <TextView android:id="@+id/line1" android:layout_width="3dp" android:layout_height="match_parent" android:layout_marginLeft="15dp" android:background="#62b0b3" /> <TextView android:id="@+id/group_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/line1" android:text="精彩推荐" android:textColor="#fff" android:textSize="22sp" /> </RelativeLayout> </LinearLayout>synopsis_item.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"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/synopsis" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ddd" android:textSize="17sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/synopsis" android:layout_margin="10dp" android:text="展开" android:textColor="#fff" android:textSize="20dp" /> </RelativeLayout> <TextView android:id="@+id/you_like" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="猜你喜欢" android:textColor="#fff" android:textStyle="bold" android:textSize="20sp" android:layout_margin="5dp" /> <android.support.v7.widget.RecyclerView android:id="@+id/recy_view" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </LinearLayout> </ScrollView> </LinearLayout>绘画背景色:
found_shap.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="270" android:centerColor="#026693" android:endColor="#023d5d" android:startColor="#1989a1" /> </shape>edittext_shap.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#fff" /> <stroke android:width="1dip" android:color="#ddd"/> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topRightRadius="5dp" android:topLeftRadius="5dp"/> <gradient android:angle="270" android:endColor="#50000000" android:startColor="#50000000" /> </shape>