Android Wear 2D Picker,如何控制看车到哪一栏

Android Wear 2D Picker, how to control which column to go to when viewing car

我正在尝试使用 2D 选择器实现卡片页面。 我怎样才能显示以下内容: 如果我在第 1 列,向上或向下滑动时,它会回到第 0 列; 如果我在第 2 列,向上或向下滑动时,它会停留在第 2 列。

您的 GridPagerAdapter 可以覆盖 getCurrentColumnForRow():

Returns the column to arrive at when navigating vertically to the specified row.

The default implementation simply returns 0.

因此你可以这样写:

public int getCurrentColumnForRow (int row, int currentColumn) {
  return currentColumn;
}

如果您所有的行都具有相同的列数,或者如果它们不相同则稍微复杂一些:

public int getCurrentColumnForRow (int row, int currentColumn) {
  return Math.min(getColumnCount(row)-1, currentColumn);
}