专注于回收站查看项目 [英] Focusing on a recyclerview item

查看:79
本文介绍了专注于回收站查看项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试着眼于recyclerview的特定项目.使用recyclerview时,与listview.setSelection(position)等价.

I am trying to focus on a particular item of a recyclerview. What is the equivalent of the listview.setSelection(position) when using a recyclerview.

推荐答案

您调用RecyclerView.scrollToPosition(position),以请求RecyclerView的LayoutManager在下一次布局传递(它是异步的)期间滚动到给定位置.

You call RecyclerView.scrollToPosition(position) to request the RecyclerView's LayoutManager to scroll to the given position during the next layout pass (it's asynchronous).

要请求聚焦项目视图,该视图必须可聚焦,然后调用View.requestFocus(). 如果要在聚焦时尚未放置视图,则可以在调用onViewAttachedToWindow()后立即调用View.requestFocus().

To request focusing an item view, the view must be focusable and you call View.requestFocus(). If the view is not yet laid out at the time you want to focus it, you can call View.requestFocus() as soon as onViewAttachedToWindow() has been called.

这篇关于专注于回收站查看项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆