CleverRecyclerView
介绍:
CleverRecyclerView 是一个基于RecyclerView的扩展库,提供了与ViewPager类似的滑动效果并且添加了一些有用的特性。
运行效果:
使用说明:
-
支持横/纵向滚动
-
支持设置一页可显示的item数量
-
支持设置滚动动画的时长
-
支持设置触发滚动到下一页的阀值
-
支持页面切换的监听
在 build.gradle 加入如下依赖:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.github.luckyandyzhang:CleverRecyclerView:1.0.0'
}
activity_main.xml
<RelativeLayout 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=".MainActivity">
<io.github.luckyandyzhang.cleverrecyclerview.CleverRecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
MainActivity.java
package com.jcodecraeer.app;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import io.github.luckyandyzhang.cleverrecyclerview.CleverRecyclerView;
public class MainActivity extends AppCompatActivity {
private MyAdapter mAdapter;
private CleverRecyclerView mRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (CleverRecyclerView)findViewById(R.id.recyclerview);
//创建并设置Adapter
mAdapter = new MyAdapter();
mRecyclerView.setAdapter(mAdapter);
//一些常用的方法
//recyclerView.setScrollAnimationDuration(300);
//recyclerView.setOrientation(RecyclerView.VERTICAL);
//recyclerView.setVisibleChildCount(3);
//......
}
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
public MyAdapter() {
}
//创建新View,被LayoutManager所调用
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item,viewGroup,false);
ViewHolder vh = new ViewHolder(view);
return vh;
}
//将数据与界面进行绑定的操作
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
viewHolder.mTextView.setText("sss");
}
//获取数据的数量
@Override
public int getItemCount() {
return 9;
}
//自定义的ViewHolder,持有每个Item的的所有界面元素
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTextView;
public ViewHolder(View view){
super(view);
mTextView = (TextView) view.findViewById(R.id.text);
}
}
}
}
已下载
0