I need to detect if an element inside a scroll is being displayed on the screen.
On my test bench I have a text lorem impsum and then a button myBtn1
To detect when scrolling in NestedScrollView
use
Button myBtn1 = (Button) findViewById(R.id.myBtn1);
NestedScrollView scroller = (NestedScrollView) findViewById(R.id.myScroll);
if (scroller != null) {
scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//aquí detectar si myBtn aparece en pantalla
}
});
}
My idea is to obtain the top
of the button and compare if the scrollY
is higher to know that the button has been viewed, taking into account the height of the scroll element, as well as to see if the button has disappeared at the top .
I wonder if there is any function in Java to determine if an element is visible / drawn on the screen?