gpt4 book ai didi

android - RecyclerView 上 LinearLayoutManager 的 scrollToPositionWithOffset 不起作用

转载 作者:太空狗 更新时间:2023-10-29 16:33:37 25 4
gpt4 key购买 nike

我正在尝试使用 RecyclerView 制作一个水平的粘性图像列表,我想用 scrollToPositionWithOffset 将它们移动像素偏移量。 .我想传递 0 作为 position 和我想向右/向左移动的像素作为 offset

但它不起作用,列表保持不变,未滚动,它不会移动。这是我的实现:

final LargeImageAdapter mLargeImageAdapter = new LargeImageAdapter(this);
linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(mLargeImageAdapter);

seekBar = (SeekBar)findViewById(R.id.seekBar);
seekBar.setMax(7000);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int scrollToDX = progress;

((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(0, scrollToDX);
// tried invoking also linearLayoutManager instead getLayoutManager.
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

我做错了什么?

非常感谢。

问候。

拉斐尔。

最佳答案

我终于使用了:

recyclerView.scrollBy(int offsetX, int offsetY); 设置 offsetY = 0 现在可以使用了。

我不明白 scrollToPositionWithOffset 函数有什么用。

关于android - RecyclerView 上 LinearLayoutManager 的 scrollToPositionWithOffset 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com