Android: how to check if a View inside of ScrollView is visible?
Use View#getHitRect
instead of View#getDrawingRect
on the view you're testing. You can use View#getDrawingRect
on the ScrollView
instead of calculating explicitly.
Code from View#getDrawingRect
:
public void getDrawingRect(Rect outRect) {
outRect.left = mScrollX;
outRect.top = mScrollY;
outRect.right = mScrollX + (mRight - mLeft);
outRect.bottom = mScrollY + (mBottom - mTop);
}
Code from View#getHitRect
:
public void getHitRect(Rect outRect) {
outRect.set(mLeft, mTop, mRight, mBottom);
}
Check a child view visible on screen or not in NestedScrollview
You can use next code:
Rect mReact = new Rect();
scrollView.getHitRect(mReact);
if (mView.getLocalVisibleRect(mReact)) {
// visible
} else {
// invisible
}
Determine which view items are visible and most centered in a horizontal scrollview in android?
to determine if a View is visible you can do this like Bill Mote
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (imageView.getLocalVisibleRect(scrollBounds)) {
// Any portion of the imageView, even a single pixel, is within the visible window
} else {
// NONE of the imageView is within the visible window
}
is stated as answer to this question Android: how to check if a View inside of ScrollView is visible?
there you can play to see which one is more centered with a little math and the order in which you added your views
Related Topics
Error:(1, 0) Plugin With Id 'Com.Android.Application' Not Found
Android - Sms Broadcast Receiver
How to Display a List View in an Android Alert Dialog
How to Animate Recyclerview Items When They Appear
Android API 21 Toolbar Padding
Warning: This Asynctask Class Should Be Static or Leaks Might Occur
Accessing External Storage in Android API 29
How to Display a Dialog from a Service
How to Run a Method Every X Seconds
Programmatically Go Back to the Previous Fragment in the Backstack
How to Disable Mobile Data on Android
How to Check Grants Permissions At Run-Time
How to Check If Alarmmanager Already Has an Alarm Set
How to Align Views at the Bottom of the Screen
Android - Camera Preview Is Sideways
How to Create Circular Progressbar in Android
Android Studio's Project Gradle File Changed
Simplecursortreeadapter and Cursorloader for Expandablelistview