とあるAndroid 案件で使ったRecyclerView の使い方のメモ。 RecyclerView でスクロールを行った時に、子要素を常に中心に配置するように補正する方法 TL;DR LinearSnapHelper を使えば良い 全文は GitHub 参照 やりたいこと RecyclerView でスクロールした時に、一番中心に近い要素をいい感じに中心に寄せてとめて欲しい。 通常 やりたいこと 方法: LinearSnapHelper を使う LinearSnapHelper のインスタンスを作成して、それを該当の RecyclerView に設定するだけ。とても簡単です。 // To make item center val snapHelper = LinearSnapHelper() snapHelper.attachToRecyclerView(recyclerView) R
![AndroidのRecyclerViewで子要素を中心にスクロールさせる | 田舎からGeekを目指す](https://cdn-ak-scissors.b.st-hatena.com/image/square/ee1aba1603f74cc0c8d287adbd1ed09cdb607f38/height=288;version=1;width=512/https%3A%2F%2Fryuta46.com%2Fwp-content%2Fuploads%2F2019%2F02%2Feyecatch.001-644x338.png)