我有一组应该在列表中填充的项目,因为我使用了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);
这可能会出错?
看起来你没有使用你在第二行声明的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);