Example usage for android.view ViewGroup requestChildFocus

List of usage examples for android.view ViewGroup requestChildFocus

Introduction

In this page you can find the example usage for android.view ViewGroup requestChildFocus.

Prototype

@Override
    public void requestChildFocus(View child, View focused) 

Source Link

Usage

From source file:org.chromium.chrome.browser.widget.animation.FocusAnimator.java

/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null)
        return;//  ww w  .  j  av a  2  s  .  c om

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null)
        parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax)
        parent.setScrollY(scrollMax);
}