parallax android,android-parallax-recyclerview

和飞翔
2023-12-01

创建list对象并传递给ParallaxRecyclerAdapterList myContent = new ArrayList(); // or another object list

ParallaxRecyclerAdapter myAdapter = new ParallaxRecyclerAdapter(myContent); // pass the list to the constructor

实现ParallaxRecyclerAdapter.RecyclerAdapterMethodsmyAdapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {

@Override

public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, 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 onCreateViewHolder(ViewGroup viewGroup, 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 getItemCount() {

// return the content of your array

return myContent.size();

}

});

现在设置parallax header,同时需要将RecyclerView也传递进去,以监听其scroll事件myAdapter.setParallaxHeader(LayoutInflater.from(this).inflate(

R.layout.myParallaxView, myRecycler, false), myRecyclerView);

 类似资料: