2
1

More than 1 year has passed since last update.

【kotlin】NestedScrollViewで最下部までスクロールした際に処理を実行する

Last updated at Posted at 2021-08-03

状況

NestedScrollViewで最下部までスクロールした際に処理を実行したい

解決方法

setOnScrollChangeListenerを利用してスクロール位置を検出する

 //Fragment
 it.scrollView.setOnScrollChangeListener { v, _, scrollY, _, _ ->
   it.isScrolled = (v as ViewGroup).getChildAt(0).bottom <= (scrollY + v.height)
 }


 //xml内にボタンを設置
 <data>
       <variable
           name="isScrolled"
           type="Boolean" />
 </data>

 <TextView
    android:id="@+id/button"
    android:enabled="@{isScrolled}"/>

ダウンロード.gif

拡張関数にすればもっと使いまわせそう。

setOnScrollChangeListener

2
1
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
1