0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HorizontalScrollViewのスクロール中にSwipeRefreshLayoutのリフレッシュが干渉する問題

Posted at

問題

リストを更新するUIとしてSwipeRefreshLayoutを利用します
このリスト内のセルが一部横スクロールできる場合、この横スクロール中に少しでも指が縦にぶれたら、リフレッシュがでてきて横スクロールを妨害してしまいます

device-2019-08-05-230449.png

解決

SwipeRefreshLayout#setOnChildScrollUpCallbackを利用して、リフレッシュを制御することで実現できます
またListView#canScrollListが合わせて必要になるので注意してください

GitHubサンプル

private var isDragging = false

swipeRefreshLayout.setOnChildScrollUpCallback { parent, child ->
    isDragging || listView.canScrollList(-1)
}

horizontalScrollView.setOnTouchListener { v, event ->
    when (event?.action) {
        MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
            isDragging = true
        }
        MotionEvent.ACTION_UP -> {
            isDragging = false
        }
    }
    false
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?