首页

源码搜藏网

首页 > 安卓源码 > 控件分类 > RecyclerViews >

在RecyclerView上面实现的视差效果

创建时间:2016-08-23 11:52  

在RecyclerView上面实现的视差效果
在RecyclerView上面实现的视差效果
暂无演示 立即下载

第1步:添加JitPack库来构建文件

repositories {
    maven {
        url "https://jitpack.io"
    }
}

第2步:添加的依赖

dependencies {
    compile 'com.github.kanytu:android-parallax-recyclerview:v1.7'
}

用法

(示例项目- https://github.com/kanytu/example-parallaxrecycler


	
List<String> myContent = new ArrayList<String>(); // or another object list
ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<String>(content) {
            @Override
            public void onBindViewHolderImpl(RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<String> adapter, int i) {
              // If you're using your custom handler (as you should of course) 
              // you need to cast viewHolder to it.
              ((MyCustomViewHolder) viewHolder).textView.setText(myContent.get(i)); // your bind holder routine.
            }

            @Override
            public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<String> adapter, int i) {
              // Here is where you inflate your row and pass it to the constructor of your ViewHolder
              return new MyCustomViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.myRow, viewGroup, false));
            }

            @Override
            public int getItemCountImpl(ParallaxRecyclerAdapter<String> adapter) {
              // return the content of your array
              return myContent.size();
            }
        };

	
myAdapter.setParallaxHeader(LayoutInflater.from(this).inflate(
    R.layout.myParallaxView, myRecycler, false), myRecyclerView);

在那里,你可以实现一些其他的听众:

//事件触发当你点击该适配器的项目。
oid onClick(View v, int position); 
//事件触发时的视差被滚动。
void onParallaxScroll(float percentage, float offset, View parallax); 

结果

ParallaxListView

很酷的效果你可以用这个库


	
@Override
public void onParallaxScroll(float percentage, float offset, View parallax) {
  Drawable c = mToolbar.getBackground();
  c.setAlpha(Math.round(percentage * 255));
  mToolbar.setBackground(c);
}

ParallaxListView

上一篇:基于SuperSlim项目,以及Reaml封装的RecyclerView
下一篇:Android用简易的方式操作RecyclerView中的分割线(ItemDecoratio

相关内容

热门推荐