2014-04-23 121 views
6

我有一个滚动型等被定义:滚动型:检查是否视图是在屏幕上可见或不可见

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

     <!-- content --> 

    </LinearLayout> 
</ScrollView> 

我填写的LinearLayout动态与一些ImageViews。现在,有没有办法来检查ImageView何时可见或不可见(例如,当我向下滚动)?

+2

退房这样的回答:[http://stackoverflow.com/a/12428208/798634](http://stackoverflow.com/a/12428208/798634) –

+0

此信息可能帮助:[http://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible][1] [1] :http://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible –

+0

检查这个答案 https://stackoverflow.com/questions/4628800/Android的如何做 - 检查 - 如果-A-视图内 - 的 - 滚动视图,是可见/ 47280300#47280300 – Himanshu

回答

10

要检查的观点是完全/部分可见,你可以使用:

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 
} 
0

我会把你to this answer

如果图像是布局的一部分,它可能是“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 
} 
相关问题