src/main/java/de/blau/android/util/Util.java
/**
     * Scroll to the supplied view
     * 
     * @param sv the ScrollView or NestedScrollView to scroll
     * @param row the row to display, if null scroll to top or bottom of sv
     * @param up if true scroll to top if row is null, otherwise scroll to bottom
     * @param force if true always try to scroll even if row is already on screen
     */
Scroll to the supplied view

@param sv the ScrollView or NestedScrollView to scroll
@param row the row to display, if null scroll to top or bottom of sv
@param up if true scroll to top if row is null, otherwise scroll to bottom
@param force if true always try to scroll even if row is already on screen
Scroll to the supplied view @param sv the ScrollView or NestedScrollView to scroll @param row the row to display if null scroll to top or bottom of sv @param up if true scroll to top if row is null otherwise scroll to bottom @param force if true always try to scroll even if row is already on screen
public static void scrollToRow(@NonNull final View sv, @Nullable final View row, final boolean up, boolean force) {
        Rect scrollBounds = new Rect();
        sv.getHitRect(scrollBounds);
        Log.d(DEBUG_TAG, "scrollToRow bounds " + scrollBounds);
        if (row != null && row.getLocalVisibleRect(scrollBounds) && !force) {
            return; 
        }
        if (row == null) {
            Log.d(DEBUG_TAG, "scrollToRow scrolling to top or bottom");
            sv.post(() -> {
                if (sv instanceof ScrollView) {
                    ((ScrollView) sv).fullScroll(up ? View.FOCUS_UP : View.FOCUS_DOWN);
                } else if (sv instanceof NestedScrollView) {
                    ((NestedScrollView) sv).fullScroll(up ? View.FOCUS_UP : View.FOCUS_DOWN);
                } else {
                    Log.e(DEBUG_TAG, "scrollToRow unexpected view " + sv);
                }
            });
        } else {
            Log.d(DEBUG_TAG, "scrollToRow scrolling to row");
            sv.post(() -> {
                final int target = up ? row.getTop() : row.getBottom();
                if (sv instanceof ScrollView) {
                    ((ScrollView) sv).smoothScrollTo(0, target);
                } else if (sv instanceof NestedScrollView) {
                    ((NestedScrollView) sv).smoothScrollTo(0, target);
                } else {
                    Log.e(DEBUG_TAG, "scrollToRow unexpected view " + sv);
                }
            });
        }
    }
public static void scrollToRow ( @ NonNull final View sv , @ Nullable final View row , final boolean up , boolean force ) { Rect scrollBounds = new Rect ( ) ; sv . getHitRect ( scrollBounds ) ; Log . d ( DEBUG_TAG , "scrollToRow bounds " + scrollBounds ) ; if ( row != null && row . getLocalVisibleRect ( scrollBounds ) && ! force ) { return ; } if ( row == null ) { Log . d ( DEBUG_TAG , "scrollToRow scrolling to top or bottom" ) ; sv . post ( ( ) -> { if ( sv instanceof ScrollView ) { ( ( ScrollView ) sv ) . fullScroll ( up ? View . FOCUS_UP : View . FOCUS_DOWN ) ; } else if ( sv instanceof NestedScrollView ) { ( ( NestedScrollView ) sv ) . fullScroll ( up ? View . FOCUS_UP : View . FOCUS_DOWN ) ; } else { Log . e ( DEBUG_TAG , "scrollToRow unexpected view " + sv ) ; } } ) ; } else { Log . d ( DEBUG_TAG , "scrollToRow scrolling to row" ) ; sv . post ( ( ) -> { final int target = up ? row . getTop ( ) : row . getBottom ( ) ; if ( sv instanceof ScrollView ) { ( ( ScrollView ) sv ) . smoothScrollTo ( 0 , target ) ; } else if ( sv instanceof NestedScrollView ) { ( ( NestedScrollView ) sv ) . smoothScrollTo ( 0 , target ) ; } else { Log . e ( DEBUG_TAG , "scrollToRow unexpected view " + sv ) ; } } ) ; } }
Scroll to the supplied view
Scroll to the supplied view
// already on screen