13

私はAppBarLayoutとNestedScrollViewを持っています。 NestedScrollViewをスクロールダウンするときはいつでも、AppBarLayoutはAppBarLayout Expandの直前でNestedScrollViewを停止せずに正常に拡張する必要があります。それを達成するためには第2の飛行/スクロールが必要です。AppBarLayoutでAppBarLayoutをAppBarLayout.Behaviorを使用して

私はstackoverflowをチェックし、この解決法がかなり関連していることを発見し、使用することができました。しかし、NestedScrollViewの場合はRecyclerViewです。 https://stackoverflow.com/a/32454407/3286489

私は基本的にコードを取ってわずかに変更し、速度> 8000をチェックして、以下のコードでもAppBarLayoutを実行するのに使用しました。

public final class FlingBehavior extends AppBarLayout.Behavior { 
    private boolean isPositive; 

    public FlingBehavior() { 
    } 

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

    @Override 
    public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) { 
     if (velocityY > 0 && !isPositive || velocityY < 0 && isPositive) { 
      velocityY = velocityY * -1; 
     } 

     if (target instanceof NestedScrollView && Math.abs(velocityY) > 8000) { 
      consumed = false; 
     } 
     return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed); 
    } 

    @Override 
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed) { 
     super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); 
     isPositive = dy > 0; 
    } 
} 

これは機能しますが、理想的ではありません。私は、NestedScrollViewがスクロールの上部に到達したときに、AppBarLayout上のFling(つまり、consumed = falseを返す)を開始(続行)したいだけです。どのように私はonNestedFlingでそれをチェックできますか?

ありがとうございました。

+0

こんにちはあなたは、このための任意のソリューションを持っていました...? –

+0

いいえ、私の上記の回避策にすぎません。おそらく、この問題の解決のために、問題に対する評価の高い要求が注目を集めるだろうか? – Elye

+0

確かに私はここでほぼ同じ質問を投稿しました.http://stackoverflow.com/questions/38119661/fling-with-nestedscrollview-and-appbarlayout –

答えて

1

あなたは問題が、このリポジトリ内のライブラリで解決されているNestedScrollViewそしてNestedScrollingChild

if (target instanceof NestedScrollView && Math.abs(velocityY) > 8000) { 
     consumed = false; 
    } 


    if (target instanceof NestedScrollingChild && Math.abs(velocityY) > 8000) { 
     consumed = false; 
    } 
関連する問題