如何知道视图是否在物理屏幕中显示?

问题描述 投票:2回答:1

我想知道我的布局视图何时显示在物理屏幕上。您知道在一些使用ScrollView的应用程序中,您必须向下滚动才能看到其他视图。我想知道什么时候像ButtonTextView这样的视图或其他视图在物理屏幕上显示来做一些工作。提前致谢:)

android view visibility
1个回答
3
投票

试试这个:

Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (view.getLocalVisibleRect(scrollBounds)) {
    // Any portion of the view, even a single pixel, is within the visible window
} else {
    // NONE of the view is within the visible window
}
© www.soinside.com 2019 - 2024. All rights reserved.