向上滚动布局高度应平行减小

时间:2017-04-05 11:55:29

标签: android android-layout listview material-design

我正在设计一个布局,其中Row下面有一个recyclerView 布局,当我向上滚动行布局应平行减少并固定在某个位置。第一个图像在滚动之前,第二个图像在滚动之后。

before Scrolling enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用这些令人敬畏的图书馆来完成您的工作。

1-对于ListView

  

ParallaxListView

对于RecyclerView

  

Android Parallax Recycleview

回收商视图的实施

第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);