XRecyclerView的简单使用与图片拉动字体缩放效果的实现
来源:互联网 发布:淘宝上怎么好评改差评 编辑:程序博客网 时间:2024/05/20 12:21
一、XRecyclerView的简单使用
1,依赖第三方implementation project(':xrecyclerview')与xml布局中的引入;
2,设置布局管理器
//设置布局管理器LinearLayoutManager layoutManager = new LinearLayoutManager(this);layoutManager.setOrientation(LinearLayoutManager.VERTICAL);mRecyclerView.setLayoutManager(layoutManager);
3,相关属性设置
mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); //设置刷新的样式mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate); //设置加载更多的样式mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey); //设置加载动画的箭头//设置底部加载更多显示字符串mRecyclerView.getDefaultFootView().setLoadingHint("自定义加载中提示");mRecyclerView.getDefaultFootView().setNoMoreHint("自定义加载完毕提示");// When the item number of the screen number is list.size-2,we call the onLoadMoremRecyclerView.setLimitNumberToCallLoadMore(2);4,头部可以添加head布局//加入XRecycleView的头部View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);mRecyclerView.addHeaderView(header);View header2 = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);mRecyclerView.addHeaderView(header2);5,设置AdapterlistData = new ArrayList<String>();mAdapter = new MyAdapter(listData);mRecyclerView.setAdapter(mAdapter);//设置adaptermRecyclerView.refresh();6,设置相关的几个重要的监听事件//上拉、下拉监听事件 mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { @Override public void onRefresh() { refreshTime ++; times = 0; new Handler().postDelayed(new Runnable(){ @Override public void run() { listData.clear(); for(int i = 0; i < itemLimit ;i++){ listData.add("item" + i + "after " + refreshTime + " times of refresh"); } mAdapter.notifyDataSetChanged(); mRecyclerView.refreshComplete(); } }, 1000); //refresh data here } @Override public void onLoadMore() { Log.e("aaaaa","call onLoadMore"); if(times < 2){ new Handler().postDelayed(new Runnable(){ @Override public void run() { for(int i = 0; i < itemLimit ;i++){ listData.add("item" + (1 + listData.size() ) ); } mRecyclerView.loadMoreComplete(); mAdapter.notifyDataSetChanged(); } }, 1000); } else { new Handler().postDelayed(new Runnable() { @Override public void run() { for(int i = 0; i < itemLimit ;i++){ listData.add("item" + (1 + listData.size() ) ); } mRecyclerView.setNoMore(true); mAdapter.notifyDataSetChanged(); } }, 1000); } times ++; } }); //设置Item点击事件 mAdapter.setClickCallBack(new MyAdapter.ItemClickCallBack() { @Override public void onItemClick(int pos) { // a demo for notifyItemRemoved // TODO: 2017/12/21 one:移除// listData.remove(pos);// mRecyclerView.notifyItemRemoved(listData,pos); // TODO: 2017/12/21 two:跳转到第二个Activity startActivity(new Intent(MainActivity.this,CollapsingToolbarLayoutActivity.class)); } } );二、图片拉动字体缩放效果的实现直接贴代码了<!--todo XRecycleView、CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout共同实现图片拉动与字体缩放效果--><!--todo 其中AppBarLayout的使用要引入jar包:com.android.support:appcompat-v7:26.0.0--><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:fitsSystemWindows="true" android:src="@drawable/headimg" app:layout_collapseMode="parallax" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_collapseMode="pin" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <com.jcodecraeer.xrecyclerview.XRecyclerView android:id="@+id/recyclerview" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="fill_parent" android:layout_height="fill_parent" /></android.support.design.widget.CoordinatorLayout>demo下载地址猛戳这里
阅读全文
0 0
- XRecyclerView的简单使用与图片拉动字体缩放效果的实现
- XRecyclerView 的简单使用
- XRecyclerView与轮播图的使用
- jQuery实现图片展开缩放的效果
- Android XRecyclerview的简单使用步骤
- 简单实现谷歌地图的图片缩放,移动效果的JS
- XRecyclerView的使用
- XRecyclerView的使用
- XRecyclerView的使用
- Xrecyclerview的使用
- 带缩放动画效果的图片切换的功能实现
- 使用WPF Resource以及Transform等技术实现鼠标控制图片缩放和移动的效果
- 使用Matlab实现对图片的缩放
- 使用Matlab实现对图片的缩放
- iOS 使用UIScrollView实现图片的缩放
- [vb.net]使用GDI+绘图达到图片随鼠标缩放与移动的效果
- 实现图片的缩放
- 缩放图片:Matrix与Bitmap的使用
- OSGI入门实例讲解(一)
- Leetcode: Reorder List
- mysql数据库的导入和导出
- 20171221_C语言学习
- Shuttle安装以及配置简介
- XRecyclerView的简单使用与图片拉动字体缩放效果的实现
- IT风投!
- sql server和access的机制有很大的不同
- 如何1秒钟让程序员抖腿?教你10个方法!
- 服务端I/O性能大比拼:Node、PHP、Java、Go
- 用过的几款步进电机驱动IC
- 《利用Python进行数据分析》第7章 字符串操作与正则表达式
- 系统分析师--经济管理2:企业相关--企业文化
- kafka数据同步Elasticsearch深入详解