LoginSignup
2
2

More than 5 years have passed since last update.

AppBarLayout+ViewPagerでAppBarLayoutへのドラッグが効かなくなることがあった

Posted at

CoordinatorLayoutの中にAppBarLayout、ViewPagerの構造で、ViewPagerのページを切り替えるとAppBarLayoutへのドラッグが効かなくなることがあった。
AppBarLayoutはCollapsingToolbarLayoutを持っていて、CollapsingToolbarLayoutはImageViewやCustomViewなどを持っている。
ViewPagerはTabLayoutを使い、コンテンツはRecyclerViewでリストを表示している。

AppBarLayoutに独自のBehaviorをセットしていたが、そもそもonNestedScroll等のメソッドが呼ばれなくなっていてた。

ということでAppBarLayoutにセットしているBehaviorのコンストラクタでsetDragCallbackを使い、trueを返すと正しく動くようになった。
原因はわからないままで気持ち悪いけど、これで解決

    public Behavior(Context context, AttributeSet attrs) {
        super(context, attrs);
        setDragCallback(new DragCallback() {
            @Override
            public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
                return true;
            }
        });
    }
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2