2016-09-10 25 views
5

Tôi có một hình ảnh collapsableToolBar layout.The bên trong tolbar bị thu gọn và trượt nhưng các mục trong chế độ xem tái chế không bị thu hẹp, chúng chỉ ở vị trí của chúng. di chuyển lên trên và sụp đổ.Thanh công cụ có thể thu gọn không được thu gọn đúng cách khi có chế độ xem tái chế bên trong nó

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:animateLayoutChanges="true" 
     > 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/collapps_bar" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      > 
      <View 
       android:id="@+id/image" 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       app:layout_collapseMode="parallax" 
       android:background="@android:color/transparent" 
       /> 
      <include layout="@layout/toolbar" /> 
      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:id="@+id/recyClerView" 
       app:layout_collapseMode="parallax" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="100dp" 
       android:orientation="horizontal" /> 
     </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 
+0

Hi chồng Learner, bạn đã tìm ra câu trả lời? Nếu không, đó là chính xác những gì tôi nói? cảm ơn! – Jaco

Trả lời

0

Tôi không biết nếu bạn quản lý để làm điều đó, nhưng tôi sẽ đề nghị bạn phải làm gì nếu bạn không làm.

Thứ nhất, thay đổi fill_parent-match_parent vì fill_parent bị phản đối bắt đầu từ API Cấp 8.

As Nikoloz Akhvlediani said on his answer, bạn có thể sử dụng phương pháp addOnItemTouchListener sử dụng xem tái chế của bạn recyClerView, và sau đó, hãy gọi đến onInterceptTouchEvent để có được những sự kiện liên lạc và requestDisallowInterceptTouchEvent để không cho phép các sự kiện cảm ứng từ chế độ xem của người tái chế và nhận cuộn mong muốn.

Ví dụ, trên onCreate() phương pháp, bạn có thể thêm mã này

recyClerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { // Listen to all actions 
     @Override 
     public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 
      int action = e.getAction(); 
      switch (action) { 
       case MotionEvent.ACTION_MOVE: // If you get some movement from a mouse, pen, finger or trackball 
        rv.getParent().requestDisallowInterceptTouchEvent(true); 
        break; 
      } 
      return false; 
     } 

     @Override 
     public void onTouchEvent(RecyclerView rv, MotionEvent e) { 

     } 

     @Override 
     public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 

     } 
    }); 

Hope this helps :)

Các vấn đề liên quan