如何通过与搜索栏交互来滑动列表视图

How to slide a listview by interacting with seekbar

我有一个列表视图和一个搜索栏,我希望列表视图根据与搜索栏的交互做出反应。

例如:- 如果将搜索栏拖动到两端,列表视图应自动向上或向下。

非常感谢任何帮助。

您应该可以使用列表视图方法: smoothScrollToPosition(int)OnSeekBarChangeListener

在您的搜索栏上设置一个 OnSeekBarChangeListener。 在 onProgressChanged 中添加使用 smoothScrollToPosition 的代码来更新 listvew 位置。 像这样:

public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {
    listView.smoothScrollToPosition(progress); //assuming you have a 1 seekbar position for each row in the list, otherwise you'll need to do some calculation to compute the new list view position.
}

或者,如果您只想滚动到用户在搜索栏中触摸的最终位置,则可以使用 onStopTrackingTouch 方法。