Skip to content

Instantly share code, notes, and snippets.

@dyguests
Created April 25, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyguests/78a0ec9c575c9c6c97f11812f7ae2069 to your computer and use it in GitHub Desktop.
Save dyguests/78a0ec9c575c9c6c97f11812f7ae2069 to your computer and use it in GitHub Desktop.
android ViewUtil

android ViewUtil

import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by fanhl on 2017/4/25.
*/
public class ViewUtil {
private static boolean isViewVisible(View child, ViewGroup parent) {
Rect scrollBounds = new Rect();
parent.getDrawingRect(scrollBounds);
float top = child.getY();
float bottom = top + child.getHeight();
if (scrollBounds.top < top && scrollBounds.bottom > bottom) {
return true; //View is visible.
} else {
return false; //View is NOT visible.
}
}
static boolean isViewHigher(View child, ViewGroup parent) {
Rect scrollBounds = new Rect();
parent.getDrawingRect(scrollBounds);
float top = child.getY();
float bottom = top + child.getHeight();
if (/*scrollBounds.top < top &&*/ scrollBounds.bottom > bottom) {
return true; //View is visible.
} else {
return false; //View is NOT visible.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment