我在活动 UI 中添加片段以及标签。所以它看起来像可滚动的 UI 列表。在 onResume 活动中,我只想获取屏幕上显示的片段。
因此,例如 UI 列表中有 10 个片段,用户在 Ui 上只能看到其中的 5 个,并且在滚动时可以看到剩余的片段。
我想要前 5 个可见的片段。这是马代码。
@Override
protected void onResume() {
super.onResume();
Fragment listitemFragment = getSupportFragmentManager().findFragmentByTag(TAG);
if(listitemFragment != null && listitemFragment.isVisible()) {
//my code
}
}
isVisible() 对所有 10 个片段都返回 true,即使用户只能在屏幕上看到 5 个片段。请帮我。这是正确的做法吗?有什么不同的方法吗?还是我做错了什么?
提前致谢