Example usage for android.widget ListView smoothScrollBy

List of usage examples for android.widget ListView smoothScrollBy

Introduction

In this page you can find the example usage for android.widget ListView smoothScrollBy.

Prototype

public void smoothScrollBy(int distance, int duration) 

Source Link

Document

Smoothly scroll by distance pixels over duration milliseconds.

Usage

From source file:com.juick.android.ThreadFragment.java

public void scrollMessages(int delta) {
    String scollMode = sp.getString("keyScrollMode", "page");
    ListView lv = getListView();
    if (lv.getChildCount() == 1 && scollMode.equals("message"))
        scollMode = "page";
    if (scollMode.equals("message")) {
        int firstVisiblePosition = lv.getFirstVisiblePosition();
        if (delta == +1) {
            if (firstVisiblePosition == 0) {
                firstVisiblePosition++; // list separator
            }/*from w w  w. ja va2  s.  co m*/
            lv.setSelection(firstVisiblePosition + 1);
        } else {
            if (firstVisiblePosition != 0) {
                lv.setSelection(firstVisiblePosition - 1);
            }
        }
    }
    if (scollMode.equals("page")) {
        if (delta == +1) {
            lv.smoothScrollBy((int) (lv.getHeight() * 0.93), 200);
        } else {
            lv.smoothScrollBy(-(int) (lv.getHeight() * 0.93), 200);
        }
    }
}

From source file:com.juick.android.MessagesFragment.java

public void scrollMessages(int delta) {
    if (getActivity() == null)
        return;//from   ww  w.  ja  v  a2 s  . co  m
    if (sp == null)
        sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String scollMode = sp.getString("keyScrollMode", "page");
    ListView lv = getListView();
    if (lv == null)
        return;
    if (lv.getChildCount() == 1 && scollMode.equals("message"))
        scollMode = "page";
    if (scollMode.equals("message")) {
        int firstVisiblePosition = lv.getFirstVisiblePosition();
        if (delta == +1) {
            lv.setSelection(firstVisiblePosition + 1);
        } else {
            if (firstVisiblePosition != 0) {
                lv.setSelection(firstVisiblePosition - 1);
            }
        }
    }
    if (scollMode.equals("page")) {
        if (delta == +1) {
            lv.smoothScrollBy((int) (lv.getHeight() * 0.93), 200);
        } else {
            lv.smoothScrollBy(-(int) (lv.getHeight() * 0.93), 200);
        }
    }
}