setPreserveFocusAfterLayout

open fun setPreserveFocusAfterLayout(preserveFocusAfterLayout: Boolean)(source)

Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not.

Usually, LayoutManagers keep focused views visible before and after layout but sometimes, views may lose focus during a layout calculation as their state changes or they are replaced with another view due to type change or animation. In these cases, RecyclerView can request focus on the new view automatically.

Parameters

preserveFocusAfterLayout

Whether RecyclerView should preserve focused Item during a layout calculations. Defaults to true.

See also