我有一组应该在列表中填充的项目,因为我使用了WearableRecyclerView.在某些情况下,我希望特定的项目成为焦点以供选择.我正在使用WearableLinearLayoutManager的scrollToPosition()方法,但监视列表不会滚动到所需的位置,但是在使用RecyclerView和scrollLooutManager的scrollToPosition()的手机上也是如此,它设置为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);