Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Scrollview:检查视图是否在屏幕上可见_Android_Android Scrollview - Fatal编程技术网

Android Scrollview:检查视图是否在屏幕上可见

Android Scrollview:检查视图是否在屏幕上可见,android,android-scrollview,Android,Android Scrollview,我有一个滚动视图,定义如下: <ScrollView ... .../> <LinearLayout ... ...> <!-- content --> </LinearLayout> </ScrollView> 我用一些图像视图动态地填充线性布局。现在,是否有方法检查图像视图何时可见或不可见(例如,当我向下滚动时)?要检查视图是否完全/部分可见

我有一个滚动视图,定义如下:

<ScrollView
    ... 
    .../>
    <LinearLayout
        ...
        ...>

        <!-- content -->

    </LinearLayout>
</ScrollView>


我用一些图像视图动态地填充线性布局。现在,是否有方法检查图像视图何时可见或不可见(例如,当我向下滚动时)?

要检查视图是否完全/部分可见,可以使用:

boolean isViewVisible = view.isShown();
要确定其是否完全可见,请使用以下方法:

Rect rect = new Rect();
if(view.getGlobalVisibleRect(rect) 
    && view.getHeight() == rect.height() 
    && view.getWidth() == rect.width() ) {
    // view is fully visible on screen
}
我将转发给你:

如果图像是布局的一部分,它可能是“View.VISIBLE”,但这并不意味着它在可见屏幕的范围内。如果那是你想要的;这将有助于:

Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (imageView.getLocalVisibleRect(scrollBounds)) {
    // imageView is within the visible window
} else {
    // imageView is not within the visible window
}

查看此答案:此帖子可能会有所帮助:[[1]:查看此答案我可以找到一个案例进行查看(