org.hermit.android.widgets
Class HScrollView

java.lang.Object
  extended by FrameLayout
      extended by org.hermit.android.widgets.HScrollView

public class HScrollView
extends FrameLayout

Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. This class scrolls horizontally, as opposed to android.widget.ScrollView which only supports vertical scrolling.

An HScrollView is a android.widget.FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a android.widget.LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

HScrollView only supports horizontally scrolling.


Constructor Summary
HScrollView(Context context)
           
HScrollView(Context context, AttributeSet attrs)
           
 
Method Summary
 void addView(View child)
           
 void addView(View child, int index)
           
 void addView(View child, int index, ViewGroup.LayoutParams params)
           
 void addView(View child, ViewGroup.LayoutParams params)
           
 boolean arrowScroll(int direction)
          Handle scrolling in response to a left or right arrow click.
protected  int computeHorizontalScrollRange()
          The scroll range of a scroll view is the overall height of all of its children.
 void computeScroll()
           
protected  int computeScrollDeltaToGetChildRectOnScreen(Rect rect)
          Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it).
 boolean dispatchKeyEvent(KeyEvent event)
           
 boolean executeKeyEvent(KeyEvent event)
          You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.
 void fling(int velocityX)
          Fling the scroll view
protected  float getLeftFadingEdgeStrength()
           
 int getMaxScrollAmount()
           
protected  float getRightFadingEdgeStrength()
           
 boolean isFillViewport()
          Indicates whether this ScrollView's content is stretched to fill the viewport.
 boolean isSmoothScrollingEnabled()
           
protected  void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec)
           
protected  void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
           
 boolean onInterceptTouchEvent(MotionEvent ev)
           
protected  void onLayout(boolean changed, int l, int t, int r, int b)
           
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           
protected  boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
          When looking for focus in children of a scroll view, need to be a little more careful not to give focus to something that is scrolled off screen.
protected  void onSizeChanged(int w, int h, int oldw, int oldh)
           
 boolean onTouchEvent(MotionEvent ev)
           
 void requestChildFocus(View child, View focused)
           
 boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)
           
 void requestLayout()
           
 void scrollTo(int x, int y)
          
 void setFillViewport(boolean fillViewport)
          Indicates this ScrollView whether it should stretch its content height to fill the viewport or not.
 void setSmoothScrollingEnabled(boolean smoothScrollingEnabled)
          Set whether arrow scrolling will animate its transition.
 void smoothScrollBy(int dx, int dy)
          Like View#scrollBy, but scroll smoothly instead of immediately.
 void smoothScrollTo(int x, int y)
          Like scrollTo(int, int), but scroll smoothly instead of immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HScrollView

public HScrollView(Context context)

HScrollView

public HScrollView(Context context,
                   AttributeSet attrs)
Method Detail

getLeftFadingEdgeStrength

protected float getLeftFadingEdgeStrength()

getRightFadingEdgeStrength

protected float getRightFadingEdgeStrength()

getMaxScrollAmount

public int getMaxScrollAmount()
Returns:
The maximum amount this scroll view will scroll in response to an arrow event.

addView

public void addView(View child)

addView

public void addView(View child,
                    int index)

addView

public void addView(View child,
                    ViewGroup.LayoutParams params)

addView

public void addView(View child,
                    int index,
                    ViewGroup.LayoutParams params)

isFillViewport

public boolean isFillViewport()
Indicates whether this ScrollView's content is stretched to fill the viewport.

Returns:
True if the content fills the viewport, false otherwise.

setFillViewport

public void setFillViewport(boolean fillViewport)
Indicates this ScrollView whether it should stretch its content height to fill the viewport or not.

Parameters:
fillViewport - True to stretch the content's height to the viewport's boundaries, false otherwise.

isSmoothScrollingEnabled

public boolean isSmoothScrollingEnabled()
Returns:
Whether arrow scrolling will animate its transition.

setSmoothScrollingEnabled

public void setSmoothScrollingEnabled(boolean smoothScrollingEnabled)
Set whether arrow scrolling will animate its transition.

Parameters:
smoothScrollingEnabled - whether arrow scrolling will animate its transition

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)

executeKeyEvent

public boolean executeKeyEvent(KeyEvent event)
You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.

Parameters:
event - The key event to execute.
Returns:
Return true if the event was handled, else false.

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent ev)

onTouchEvent

public boolean onTouchEvent(MotionEvent ev)

arrowScroll

public boolean arrowScroll(int direction)
Handle scrolling in response to a left or right arrow click.

Parameters:
direction - The direction corresponding to the arrow key that was pressed
Returns:
True if we consumed the event, false otherwise

smoothScrollBy

public final void smoothScrollBy(int dx,
                                 int dy)
Like View#scrollBy, but scroll smoothly instead of immediately.

Parameters:
dx - the number of pixels to scroll by on the X axis
dy - the number of pixels to scroll by on the Y axis

smoothScrollTo

public final void smoothScrollTo(int x,
                                 int y)
Like scrollTo(int, int), but scroll smoothly instead of immediately.

Parameters:
x - the position where to scroll on the X axis
y - the position where to scroll on the Y axis

computeHorizontalScrollRange

protected int computeHorizontalScrollRange()

The scroll range of a scroll view is the overall height of all of its children.


measureChild

protected void measureChild(View child,
                            int parentWidthMeasureSpec,
                            int parentHeightMeasureSpec)

measureChildWithMargins

protected void measureChildWithMargins(View child,
                                       int parentWidthMeasureSpec,
                                       int widthUsed,
                                       int parentHeightMeasureSpec,
                                       int heightUsed)

computeScroll

public void computeScroll()

computeScrollDeltaToGetChildRectOnScreen

protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect)
Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it).

Parameters:
rect - The rect.
Returns:
The scroll delta.

requestChildFocus

public void requestChildFocus(View child,
                              View focused)

onRequestFocusInDescendants

protected boolean onRequestFocusInDescendants(int direction,
                                              Rect previouslyFocusedRect)
When looking for focus in children of a scroll view, need to be a little more careful not to give focus to something that is scrolled off screen. This is more expensive than the default android.view.ViewGroup implementation, otherwise this behavior might have been made the default.


requestChildRectangleOnScreen

public boolean requestChildRectangleOnScreen(View child,
                                             Rect rectangle,
                                             boolean immediate)

requestLayout

public void requestLayout()

onLayout

protected void onLayout(boolean changed,
                        int l,
                        int t,
                        int r,
                        int b)

onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)

fling

public void fling(int velocityX)
Fling the scroll view

Parameters:
velocityX - The initial velocity in the Y direction. Positive numbers mean that the finger/curor is moving down the screen, which means we want to scroll towards the top.

scrollTo

public void scrollTo(int x,
                     int y)

This version also clamps the scrolling to the bounds of our child.