文件名称:
RecyclerViewPager-一个基于RecyclerView实现的ViewPager,支持类似于gallary的fling操作.zip
开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2019-09-24
详细说明: 介绍:一个基于RecyclerView实现的ViewPager,支持类似于gallary的fling操作。点击上面"下载源码" 按钮,可以下载完整的demo。其中recyclerview是android-support中的依赖项目,RecyclerViewPager是主项目。运行效果:使用说明:继承自 RecyclerView.自定义 fling factor.自定义 paging trigger.支持 水平个垂直方向.支持 FragmentViewPager (api 12 )gradlecompile(com.lsjwzh:recyclerviewpager:1.0.2)xml:java:final RecyclerViewPager mRecyclerView = (RecyclerViewPager) this.findViewById(R.id.recyclerViewPager); LinearLayoutManager layout = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false);//LinearLayoutManager.HORIZONTAL 设置水平滚动 mRecyclerView.setLayoutManager(layout); //set adapter mRecyclerView.setAdapter(new MyRecyclerAdapter());static class MyRecyclerAdapter extends RecyclerView.Adapter { private List items = new ArrayList(); public MyRecyclerAdapter(){ //创建4个页面 for(int i = 1; i<5; i ){ items.add("页面" i); } } public static class ViewHolder extends RecyclerView.ViewHolder{ public ViewHolder(View itemView) { super(itemView); } } Override public int getItemCount() { // TODO Auto-generated method stub return items.size(); } Override public void onBindViewHolder(ViewHolder holder, int position) { String item = items.get(position); TextView msgTv = (TextView)holder.itemView.findViewById(R.id.msg); msgTv.setText(item); } Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if(inflate == null) inflate = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = (LinearLayout)(inflate.inflate(R.layout.item, null)); return new ViewHolder(v); } }如果你想增加一些切换的特效:mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener(){ Override public void onScrolled(RecyclerView recyclerView, int i, int i2) {//监听滚动,i为每次水平滚动的距离, i2为每次垂直滚动的距离 // mPositionText.setText("First: " mRecyclerView.getFirstVisiblePosition()); System.out.println("MainaActiv: i=" i " i2=" i2); //以下代码的作用是,使页面切换产生立体的效果 int childCount = mRecyclerView.getChildCount(); int width = mRecyclerView.getChildAt(0).getWidth(); int padding = (mRecyclerView.getWidth() - width) / 2; for (int j = 0; j < childCount; j ) { View v = recyclerView.getChildAt(j); //往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小 float rate = 0; ; if (v.getLeft() <= padding) { if (v.getLeft() >= padding - v.getWidth()) { rate = (padding - v.getLeft()) * 1f / v.getWidth(); } else { rate = 1; } v.setScaleY(1 - rate * 0.1f); v.setScaleX(1 - rate * 0.1f); } else { //往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小 if (v.getLeft() <= recyclerView.getWidth() - padding) { rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth(); } v.setScaleY(0.9f rate * 0.1f); v.setScaleX(0.9f rate * 0.1f); } } } }); mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (mRecyclerView.getChildCount() < 3) { if (mRecyclerView.getChildAt(1) != null) { if(mRecyclerView.getCurrentPosition()==0) { View v1 = mRecyclerView.getChildAt(1); v1.setScaleY(0.9f); v1.setScaleX(0.9f); } else { View v1 = mRecyclerView.getChildAt(0); v1.setScaleY(0.9f); v1.setScaleX(0.9f); } } } else { if (mRecyclerView.getChildAt(0) != null) { View v0 = mRecyclerView.getChildAt(0); v0.setScaleY(0.9f); v0.setScaleX(0.9f); } if (mRecyclerView.getChildAt(2) != null) { View v2 = mRecyclerView.getChildAt(2); v2.setScaleY(0.9f); v2.setScaleX(0.9f); } } } }); }
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
相关搜索: