相关疑难解决方法(0)

RecyclerView焦点滚动

我有一个RecyclerView,通常有两列,最多八列.我们使用了很多D-PAD导航.滚动时我们遇到问题,焦点项目将从左向右跳跃.看照片: 在此输入图像描述

我注意到,如果下一个出现的项目被缓存,滚动时没有焦点问题.我遇到的另一个问题是我的焦点项目可能出现在我的粘贴标题下方.这是不希望的.所以我觉得如果我滚动它就会有一个"阈值".这样,当焦点位于屏幕外的一个项目内时,它将滚动.这样,焦点永远不会位于最底层,也不会位于顶部.

考虑到这一点,我尝试了这种方法没有运气:

RecyclerView rv;

@Override
public void onFocusChange(View v, boolean hasFocus) {
    if(!v.hasFocus()) {
        Log.w(TAG, "View v did not have focus");
        return;
    }

    final int index = rv.getChildPosition(v); //adapter pos
    if(index == NO_POSITION) {
        Log.w(TAG, "Recycler view did not have view");
        return;
    }

    int position = rv.indexOfChild(v);  // layout pos
    int lastPos = rv.getChildCount();   // layout pos
    int span = getLayoutManager().getSpanCount();
    int threshold = 2 * span;
    Log.d(TAG, String.format("Position: %1$d. lastPos: %2$d. span: %3$d. threshold: %4$d", position, lastPos, span, …
Run Code Online (Sandbox Code Playgroud)

android focus android-recyclerview

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-recyclerview ×1

focus ×1