android.widget.AbsListView#getFirstVisiblePosition ( )源码实例Demo

下面列出了android.widget.AbsListView#getFirstVisiblePosition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-source-codes   文件: SwipeRefreshLayout.java
/**
 * @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 (mChildScrollUpCallback != null) {
        return mChildScrollUpCallback.canChildScrollUp(this, mTarget);
    }
    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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
public int getScrollY(AbsListView view) {
	View c = view.getChildAt(0);
	if (c == null) {
		return 0;
	}

	int firstVisiblePosition = view.getFirstVisiblePosition();
	int top = c.getTop();

	int headerHeight = 0;
	if (firstVisiblePosition >= 1) {
		headerHeight = mHeaderHeight;
	}

	return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}
 
源代码3 项目: weex-uikit   文件: WXSwipeLayout.java
/**
 * Whether child view can scroll up
 * @return
 */
public boolean canChildScrollUp() {
  if (mTargetView == null) {
    return false;
  }
  if (Build.VERSION.SDK_INT < 14) {
    if (mTargetView instanceof AbsListView) {
      final AbsListView absListView = (AbsListView) mTargetView;
      return absListView.getChildCount() > 0
             && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                                                                  .getTop() < absListView.getPaddingTop());
    } else {
      return ViewCompat.canScrollVertically(mTargetView, -1) || mTargetView.getScrollY() > 0;
    }
  } else {
    return ViewCompat.canScrollVertically(mTargetView, -1);
  }
}
 
源代码4 项目: SprintNBA   文件: TBListView.java
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
                     int visibleItemCount, int totalItemCount) {
    mFirstVisibleItem = firstVisibleItem;
    if (view.getFirstVisiblePosition() == 1) {
        mIsTop = true;
        // 滑动到顶部
    } else if (onLoadMoreListener != null && view.getLastVisiblePosition() == view.getCount() - 1) {
        mIsBottom = true;
        onLoadMoreListener.onLoadMore();
        // 滑动到底部
    } else {
        mIsTop = false;
        mIsBottom = false;
    }
}
 
源代码5 项目: NewFastFrame   文件: CustomSwipeRefreshLayout.java
/**
 * @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 (mChildScrollUpCallback != null) {
        return mChildScrollUpCallback.canChildScrollUp(this, mTarget);
    }
    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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
源代码6 项目: Typewriter   文件: TypewriterRefreshLayout.java
/**
 * @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 (onChildScrollUpCallback != null) {
        return onChildScrollUpCallback.canChildScrollUp(this, target);
    }
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (target instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) target;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 ||
                    absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(target, -1) || target.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(target, -1);
    }
}
 
源代码7 项目: MaterialQQLite   文件: PullRefreshLayout.java
private boolean canChildScrollDown() {
    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);
    }
}
 
源代码8 项目: AndroidMaterialDialog   文件: DialogRootView.java
/**
 * Returns, whether a specific list view is scrolled to the top, or not.
 *
 * @param listView The list view as an instance of the class {@link AbsListView}. The list view may not
 *                 be null
 * @return True, if the given list view is scrolled to the top, false otherwise
 */
private boolean isListViewScrolledToTop(@NonNull final AbsListView listView) {
    if (listView.getFirstVisiblePosition() == 0) {
        if (listView.getChildCount() == 0) {
            return true;
        } else {
            View child = listView.getChildAt(0);
            return child == null || child.getTop() == 0;
        }
    }

    return false;
}
 
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);
    }
}
 
源代码10 项目: Bitocle   文件: AbsListViewDelegate.java
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= absListView.getPaddingTop();
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
源代码11 项目: AndroidStudyDemo   文件: BGAScrollingUtil.java
public static boolean isAbsListViewToTop(AbsListView absListView) {
    if (absListView != null) {
        int firstChildTop = 0;
        if (absListView.getChildCount() > 0) {
            // 如果AdapterView的子控件数量不为0,获取第一个子控件的top
            firstChildTop = absListView.getChildAt(0).getTop() - absListView.getPaddingTop();
        }
        if (absListView.getFirstVisiblePosition() == 0 && firstChildTop == 0) {
            return true;
        }
    }
    return false;
}
 
源代码12 项目: narrate-android   文件: DayPickerView.java
/**
 * Updates the title and selected month if the view has moved to a new
 * month.
 */
@Override
public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    MonthView child = (MonthView) view.getChildAt(0);
    if (child == null) {
        return;
    }

    // Figure out where we are
    long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom();
    mPreviousScrollPosition = currScroll;
    mPreviousScrollState = mCurrentScrollState;
}
 
源代码13 项目: QuickReturn   文件: QuickReturnUtils.java
public static int getScrollY(AbsListView lv) {
        View c = lv.getChildAt(0);
        if (c == null) {
            return 0;
        }

        int firstVisiblePosition = lv.getFirstVisiblePosition();
        int scrollY = -(c.getTop());
//        int scrollY = 0;


        sListViewItemHeights.put(lv.getFirstVisiblePosition(), c.getHeight());

//        if(scrollY>0)
//            Log.d("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));
//        else
//            Log.i("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));

        if (scrollY < 0)
            scrollY = 0;

        for (int i = 0; i < firstVisiblePosition; ++i) {
//            Log.d("QuickReturnUtils", "getScrollY() : i - "+i);

//            Log.d("QuickReturnUtils", "getScrollY() : sListViewItemHeights.get(i) - "+sListViewItemHeights.get(i));

            if (sListViewItemHeights.get(i) != null) // (this is a sanity check)
                scrollY += sListViewItemHeights.get(i); //add all heights of the views that are gone

        }

//        Log.d("QuickReturnUtils", "getScrollY() : scrollY - "+scrollY);

        return scrollY;
    }
 
源代码14 项目: MaterialDateRangePicker   文件: DayPickerView.java
/**
 * Updates the title and selected month if the view has moved to a new
 * month.
 */
@Override
public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    MonthView child = (MonthView) view.getChildAt(0);
    if (child == null) {
        return;
    }

    // Figure out where we are
    long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom();
    mPreviousScrollPosition = currScroll;
    mPreviousScrollState = mCurrentScrollState;
}
 
源代码15 项目: EasyRefreshLayout   文件: EasyRefreshLayout.java
private boolean canChildScrollUp() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (contentView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) contentView;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(contentView, -1) || contentView.getScrollY() > 0;
        }
    } else {
        /*return true can  swipe up*/
        return ViewCompat.canScrollVertically(contentView, -1);
    }
}
 
源代码16 项目: AndroidPullMenu   文件: AbsListViewDelegate.java
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= absListView.getPaddingTop();
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
源代码17 项目: Overchan-Android   文件: SwipeRefreshLayout.java
/**
 * @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);
    }
}
 
源代码18 项目: mooc_hyman   文件: SwipeRefresh.java
/**
 * @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);
    }
}
 
源代码19 项目: CommonPullToRefresh   文件: PtrDefaultHandler.java
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;
                return ViewCompat.canScrollVertically(view, -1) || view.getScrollY() > 0;
            }
        } else {
          return view.canScrollVertically(-1);
        }
    }
 
源代码20 项目: ChipHellClient   文件: QuickReturnUtils.java
public static int getScrollY(AbsListView lv) {
        View c = lv.getChildAt(0);
        if (c == null) {
            return 0;
        }

        int firstVisiblePosition = lv.getFirstVisiblePosition();
        int scrollY = -(c.getTop());
//        int scrollY = 0;



        sListViewItemHeights.put(lv.getFirstVisiblePosition(), c.getHeight());

//        if(scrollY>0)
//            Log.d("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));
//        else
//            Log.i("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));

        if(scrollY<0)
            scrollY = 0;

        for (int i = 0; i < firstVisiblePosition; ++i) {
//            Log.d("QuickReturnUtils", "getScrollY() : i - "+i);

//            Log.d("QuickReturnUtils", "getScrollY() : sListViewItemHeights.get(i) - "+sListViewItemHeights.get(i));

            if (sListViewItemHeights.get(i) != null) // (this is a sanity check)
                scrollY += sListViewItemHeights.get(i); //add all heights of the views that are gone

        }

//        Log.d("QuickReturnUtils", "getScrollY() : scrollY - "+scrollY);

        return scrollY;
    }