2017-08-03 5 views
0

コーディネーターのカスタムビヘイビアがどのように機能するかを知りたいので、recyclerviewがスクロールするとボタンYのスケールが変更されるプロジェクトを作成しました。 これは私のxmlレイアウトです:RecyclerViewとCoordinatorLayout.Behavior

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinatorLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/mp_recycleview1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/cardview_light_background" 
     android:paddingBottom="5dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:paddingTop="5dp" 
     android:scrollbars="vertical" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/cardview_dark_background" 
      android:backgroundTint="@color/colorPrimary" 
      android:text="Button" 
      app:layout_behavior=".MyBehavior" 
      android:textColor="@android:color/white" 
      /> 
</android.support.design.widget.CoordinatorLayout> 

と、これは私の行動クラス

public class MyBehavior extends CoordinatorLayout.Behavior<Button> { 
    private final static String TAG = "MyBehavior"; 

    public MyBehavior(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    public boolean layoutDependsOn(CoordinatorLayout parent, Button child, View dependency) { 
     return dependency instanceof RecyclerView; 

    } 

    @Override 
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, Button child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { 
     child.setScaleY(((RecyclerView)target).computeVerticalScrollOffset()); 


    } 
} 

あるしかし、私はスクロールするとRecyclerViewの何も起こりません。ここ

+1

'onNestedScroll()'呼び出しを受け取るには 'onStartNestedScroll'をオーバーライドして' true'を返す必要があります。 – Wizard

+0

@Wizardありがとうございました<3 –

+0

私はこれに答えるべきですので、受け入れてください - 誰にでも役立つかもしれません – Wizard

答えて

3

ヘッズアップ、onNestedScroll()コールを受信するために

、あなたはtrueを返すようにonStartNestedScrollをオーバーライドする必要があります。

関連する問題