android - Android - 在视图调整大小时保持 recylerview 选定的项目
问题描述
我在一个活动中有两个 FrameLayouts。第一个包含recylerview 或listview,第二个包含不同的控件,具体取决于情况。
当控件添加到第二个框架布局时,我想保持用户可以看到 recylerview 中的选定项目。
选择项目时,我在Recylerview布局管理器上使用卷轴定位,但是在屏幕上可见新控件之前,这是调用的,因此RecyLerview中的所选项目可以脱离屏幕。
有谁知道我怎么能做到这一点?
解决方案
在大多数情况下,我设法让这个工作。在 onCreateView 中使用以下代码。希望这对其他人有帮助
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
{
if ((bottom < oldBottom) && currentlyPlayingFile != null && currentlyPlayingFilePos != -1)
{
if (currentlyPlayingFilePos > (mFileData.length * 0.75))
{
int moveAmount = oldBottom - bottom;
if (currentlyPlayingFilePos == (mFileData.length - 1))
moveAmount += 35;
mRecyclerView.scrollBy(0, moveAmount);
}
else
{
mRecyclerView.scrollToPosition(currentlyPlayingFilePos);
}
}
}
});
推荐阅读
- mongodb - 类似索引的 Mongo 索引策略
- python - numpy的问题点积不起作用
- linux - bash 错误突然出现在基本操作系统中
- xslt - 带有method =“text”的xslt复制元素
- angular - 如何通过缓存在 Angular 9 中的组件实例之间维护变量的值?
- ruby-on-rails - Ruby:数据没有引号,但 CSV.parse 引发 CSV::MalformedCSVError: Illegal quoting in line x
- javascript - 如何在 JavaScript 中创建健康评分计算器?
- yolo - yolo暗网框架CUDA错误:无效设备符号暗网:./src/cuda.c:36:check_error:断言“0”失败
- python - 如何打印所有值都在一个数字之间的行数
- python-3.x - dict中的字符串转换问题然后添加到列表