2015-12-12 19 views
5

Này, tôi có một cái nhìn tái chế và từng hạng mục quan điểm tái chế Chứa ImageView nào trong FrameLayout và hình ảnh Trải dài để phù hợp với tất cả các kích thước mục
gì tôi muốn làm để tạo ra hiệu ứng Parallax trên Recycler Xem mục hình ảnhLàm thế nào để tạo hiệu ứng thị sai trên Recycler Xem mục trên di chuyển?

mà tôi có thể để di chuyển hình ảnh để hiển thị một phần ẩn của nó khi tôi di chuyển lên và xuống

Giống như Tutorial này nhanh chóng

gì tôi đã làm ở đây trên Recycler Xem cuộn

events_list.addOnScrollListener(new RecyclerView.OnScrollListener() { 
     @Override 
     public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
      super.onScrollStateChanged(recyclerView, newState); 
     } 

     @Override 
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
      super.onScrolled(recyclerView, dx, dy); 
      final DynamicImageView imageView = (DynamicImageView) recyclerView.findViewById(R.id.item_image); 
      if (imageView.getVisibility() == View.VISIBLE) { 
       if (dy > 0) { 
        Animation a = new Animation() { 

         @Override 
         protected void applyTransformation(float interpolatedTime, Transformation t) { 
          FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams(); 
          params.topMargin = (int)(-50 * interpolatedTime); 
          imageView.setLayoutParams(params); 
         } 
        }; 
        a.setDuration(100); // in ms 
        imageView.startAnimation(a); 

       } else if (dy < 0) { 
        Animation a = new Animation() { 

         @Override 
         protected void applyTransformation(float interpolatedTime, Transformation t) { 
          FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams(); 
          params.topMargin = (int)(50 * interpolatedTime); 
          imageView.setLayoutParams(params); 
         } 
        }; 
        a.setDuration(100); // in ms 
        imageView.startAnimation(a); 
       } 
      } 


     } 
    }); 

Tôi biết rằng mã này không phải là giải pháp tối ưu, nó cũng cần phải kiểm tra tất cả các mục nhìn thấy không phải là đầu tiên nhưng vấn đề của tôi ở đây là thay đổi lề của hình ảnh. không hoạt động hoàn hảo
bất kỳ trợ giúp nào?

+0

có thể bạn sẽ chỉ muốn làm cho bố cục của riêng bạn/xem và không làm việc với người nghe di chuyển. Ghi đè phương thức 'onLayout' và bạn đã thiết lập. sau đó bạn có thể, tùy thuộc vào vị trí quan điểm, tự mình vẽ hình ảnh, làm sai lệch nó –

+0

Cảm ơn @ bleeding182 bạn đã đúng thư viện mà tôi đã tìm được công việc theo cách này một lần nữa nhờ – Tony

Trả lời

1

tôi tìm thấy Library này đạt được những gì tôi muốn chính xác

cách nó được sử dụng

<com.fmsirvent.ParallaxEverywhere.PEWImageView 
     android:id="@+id/grid_image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     pew:block_parallax_x="true" 
     pew:reverse="reverseY" 

     android:scaleType="centerCrop" 
     /> 
Các vấn đề liên quan