Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollview: check if a view is visible on screen or not

I have a ScrollView defined like:

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

        <!-- content -->

    </LinearLayout>
</ScrollView>

And I fill the LinearLayout dynamically with some ImageViews. Now, is there a way to check when an ImageView gets visible or invisible (for example when i scroll down)?

like image 432
giozh Avatar asked Apr 23 '14 13:04

giozh


1 Answers

To check if the view is fully/partially visible you can use :

boolean isViewVisible = view.isShown();

To determine if it is fully visible use below approach:

Rect rect = new Rect();
if(view.getGlobalVisibleRect(rect) 
    && view.getHeight() == rect.height() 
    && view.getWidth() == rect.width() ) {
    // view is fully visible on screen
}
like image 93
Akash Dubey Avatar answered Oct 20 '22 18:10

Akash Dubey