Пример #1
0
 /**
  * Copy From AbsListView (API Level >= 19)
  *
  * @param absListView AbsListView
  * @param direction Negative to check scrolling up, positive to check scrolling down.
  * @return true if the list can be scrolled in the specified direction, false otherwise
  */
 private boolean absListViewCanScrollList(AbsListView absListView, int direction) {
   final int childCount = absListView.getChildCount();
   if (childCount == 0) {
     return false;
   }
   final int firstPosition = absListView.getFirstVisiblePosition();
   if (direction > 0) { // can scroll down
     final int lastBottom = absListView.getChildAt(childCount - 1).getBottom();
     final int lastPosition = firstPosition + childCount;
     return lastPosition < absListView.getCount()
         || lastBottom > absListView.getHeight() - absListView.getPaddingTop();
   } else { // can scroll  up
     final int firstTop = absListView.getChildAt(0).getTop();
     return firstPosition > 0 || firstTop < absListView.getPaddingTop();
   }
 }
 @Override
 public boolean isScrollableChildUnscrolled() {
   final AbsListView listView = getCurrentListView();
   return listView != null
       && (listView.getChildCount() == 0
           || listView.getChildAt(0).getTop() == listView.getPaddingTop());
 }
Пример #3
0
  public boolean canChildScrollUp() {
    if (Build.VERSION.SDK_INT < 14) {
      if ((this.mTarget instanceof AbsListView)) {
        AbsListView absListView = (AbsListView) this.mTarget;
        return (absListView.getChildCount() > 0)
            && ((absListView.getFirstVisiblePosition() > 0)
                || (absListView.getChildAt(0).getTop() < absListView.getPaddingTop()));
      }

      return (ViewCompat.canScrollVertically(this.mTarget, -1)) || (this.mTarget.getScrollY() > 0);
    }

    return ViewCompat.canScrollVertically(this.mTarget, -1);
  }
 /**
  * @return Whether it is possible for the child view of this layout to scroll up. Override this if
  *     the child view is a custom view.
  */
 public boolean canChildScrollUp() {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (mTarget instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) mTarget;
       return absListView.getChildCount() > 0
           && (absListView.getFirstVisiblePosition() > 0
               || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
     } else {
       return mTarget.getScrollY() > 0;
     }
   } else {
     return ViewCompat.canScrollVertically(mTarget, -1);
   }
 }
Пример #5
0
 public static boolean canChildScrollUp(View view) {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (view instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) view;
       return absListView.getChildCount() > 0
           && (absListView.getFirstVisiblePosition() > 0
               || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
     } else {
       return view.getScrollY() > 0;
     }
   } else {
     return view.canScrollVertically(-1);
   }
 }
Пример #6
0
  /**
   * get AbsListView height according to every children
   *
   * @param view
   * @return
   */
  public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
      return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
      View item = adapter.getView(i, null, view);
      if (item instanceof ViewGroup) {
        item.setLayoutParams(
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      }
      item.measure(0, 0);
      height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
  }
Пример #7
0
 public static boolean canViewScrollUp(View view) {
   if (view == null) {
     return false;
   }
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
     if (view instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) view;
       if (absListView.getChildCount() == 0) {
         return false;
       }
       return absListView.getFirstVisiblePosition() > 0
           || absListView.getChildAt(0).getTop() < absListView.getPaddingTop();
     } else {
       return view.getScrollY() > 0;
     }
   } else {
     return ViewCompat.canScrollVertically(view, -1);
   }
 }