diff options
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index f641c96552cf..acea3e79e6e0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -21608,6 +21608,8 @@ package android.view { method public void buildDrawingCache(); method public void buildDrawingCache(boolean); method public void buildLayer(); + method public boolean canScrollHorizontally(int); + method public boolean canScrollVertically(int); method public void cancelLongPress(); method public boolean checkInputConnectionProxy(android.view.View); method public void clearAnimation(); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index ee187222e622..071905c1299d 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -8457,6 +8457,40 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit } /** + * Check if this view can be scrolled horizontally in a certain direction. + * + * @param direction Negative to check scrolling left, positive to check scrolling right. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollHorizontally(int direction) { + final int offset = computeHorizontalScrollOffset(); + final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + + /** + * Check if this view can be scrolled vertically in a certain direction. + * + * @param direction Negative to check scrolling up, positive to check scrolling down. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollVertically(int direction) { + final int offset = computeVerticalScrollOffset(); + final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + + /** * <p>Request the drawing of the horizontal and the vertical scrollbar. The * scrollbars are painted only if they have been awakened first.</p> * |