View到达顶部及底部边界判断

/**
* 判断View是否滑动到顶部
* @param view
* @return
*/
public static boolean isViewReachTopEdge(View view) {
if (view instanceof ViewGroup) {
if (view.canScrollVertically(-1))
return false;
int count = ((ViewGroup)view).getChildCount();
for (int i = 0; i < count; i++) {
if (!isViewReachTopEdge(((ViewGroup)view).getChildAt(i)))
return false;
}
}
if (view.canScrollVertically(-1)) {
return false;
}
return true;
}

/** 
 * 判断View是否滑动到底部 
 * @param view 
 * @return 
 */  
public static boolean isViewReachBottomEdge(View view) {  
    if (view instanceof ViewGroup) {  
        if (view.canScrollVertically(1))  
            return false;  
        int count  = ((ViewGroup)view).getChildCount();  
        for (int i = 0; i < count; i++) {  
            if (!isViewReachBottomEdge(((ViewGroup)view).getChildAt(i)))  
                return false;  
        }  
    }  
    if (view.canScrollVertically(1)) {  
        return false;  
    }  
    return true;  
}  

猜你喜欢

转载自blog.csdn.net/wangkaiblog/article/details/80342440
今日推荐