Пример #1
0
  /**
   * listViewSetScroll
   *
   * @param position
   */
  private void listViewSetScroll(int position) {

    int itemHeight = getItemHeight(mListView);
    float temp = mListView.getHeight() / (float) getItemHeight(mListView);
    int visibleItem = (int) Math.ceil(temp);
    int maxItemTop = mAdapter.getCount() - visibleItem;

    if (position <= maxItemTop) {
      mDy = 0;
      mListView.smoothScrollToPositionFromTop(position, 0, 2000);
    } else {

      int incompleteItemheight = mListView.getHeight() - (visibleItem - 1) * itemHeight;
      mDy = itemHeight * (position - maxItemTop - 1) + incompleteItemheight;
      Log.e(TAG, "maxItemTop " + maxItemTop + " incompleteItemheight " + incompleteItemheight);
      // mListView.smoothScrollToPositionFromTop(maxItemTop, 0, 1000);
      // mListView.smoothScrollToPosition(maxItemTop-1);
      mListView.setSelection(mListView.getBottom());
      // mListView.animate().translationY(-mDy).setDuration(2000);
      mUIHandler.sendEmptyMessageDelayed(UPDATE_LISTVIEW_SCROLL, 1500);
    }
  }