视图在屏幕上的位置

Position of views on the screen

如何检测位于scrollview(linearlayout)中的cardview是否超出屏幕或返回视野? 我试图通过 OnScrollChanged 做到这一点但在我看来,情况并非如此,并且不可能获得正确的工作算法

您必须在 CardView:

上使用方法 getLocalVisibleRect()
Rect scrollViewRect = new Rect();
// Get the visible Rect of the ScrollView.
scrollView.getHitRect(scrollViewRect);
// Check if CardView's Rect is inside it.
if (!cardView.getLocalVisibleRect(scrollViewRect)) {
    // The CardView is not visibile anymore.
}

您可以将此代码放在任何您想要检查 CardView 是否在屏幕上不再可见的位置。