android ViewUtil
Created
April 25, 2017 11:41
-
-
Save dyguests/78a0ec9c575c9c6c97f11812f7ae2069 to your computer and use it in GitHub Desktop.
android ViewUtil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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