9

我有一组项目应该填充到列表中,因为我已经使用了WearableRecyclerView. 在某些情况下,我希望特定项目成为选择的焦点。我正在使用scrollToPosition()的方法,WearableLinearLayoutManager但监视列表不滚动到所需的位置,但在手机上使用的相同的东西RecyclerView设置scrollToPosition()LinearLayoutManager工作RecyclerView并滚动到所需的位置。

我的手表代码:

WearableRecyclerView slots_rv = findViewById(R.id.slots_rv);
.....


WearableLinearLayoutManager wearableLinearLayoutManager =
    new WearableLinearLayoutManager(this, customScrollingLayoutCallback);
slots_rv.setLayoutManager(
    wearableLinearLayoutManager);

slots_rv.setCircularScrollingGestureEnabled(true);
wearableLinearLayoutManager.scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.getLayoutManager().scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.setAdapter(slotsAdapter);

这里可能出了什么问题?

4

2 回答 2

1

看起来您没有使用您在第二行中声明的 WearableLinearLayoutManager。您将 LayoutManager 设置为一个新实例,因此调用 scrollToPosition 将不起作用。尝试以下

    WearableLinearLayoutManager wearableLinearLayoutManager = new WearableLinearLayoutManager(this, customScrollingLayoutCallback);
    slots_rv.setLayoutManager(wearableLinearLayoutManager);

    slots_rv.setCircularScrollingGestureEnabled(true);

    wearableLinearLayoutManager.scrollToPosition(slotsAdapter.getPositionToFocus());
    slots_rv.setAdapter(slotsAdapter);
于 2018-09-04T13:08:20.783 回答
0

这对我有用。alist 是wearablerecyclerview。

WearableLinearLayoutManager wearableLinearLayoutManager = new WearableLinearLayoutManager(this);
        alist.setLayoutManager(wearableLinearLayoutManager);
        wearableLinearLayoutManager.setSmoothScrollbarEnabled(true);
        wearableLinearLayoutManager.smoothScrollToPosition(alist, new RecyclerView.State(),3);
于 2021-01-09T02:09:30.443 回答