答案 0 :(得分:0)
您可以使用这些令人敬畏的图书馆来完成您的工作。
1-对于ListView
对于RecyclerView
回收商视图的实施
第1步。将JitPack存储库添加到构建文件
repositories {
maven {
url "https://jitpack.io"
}
}
第2步。添加依赖项
dependencies {
compile 'com.github.kanytu:android-parallax-recyclerview:v1.7'
}
<强> USAGE 强> (示例项目 - https://github.com/kanytu/example-parallaxrecycler)
创建对象列表并将其传递给ParallaxRecyclerAdapter
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();
}
};`
现在我们设置视差标头。您还需要传递RecyclerView
来实现滚动侦听器。
myAdapter.setParallaxHeader(LayoutInflater.from(this).inflate(R.layout.myParallaxView, myRecycler, false), myRecyclerView);
您可以实施其他一些听众:
// Event triggered when you click on a item of the adapter.
void onClick(View v, int position);
// Event triggered when the parallax is being scrolled.
void onParallaxScroll(float percentage, float offset, View parallax);