static boolean listIsAtTop(AbsListView listView) { return listView.getChildCount() == 0 || listView.getChildAt(0).getTop() == listView.getPaddingTop(); }
public boolean canScrollUp(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 ViewCompat.canScrollVertically(view, -1); } }
/** * 判断目标View是否滑动到顶部-还能否继续滑动 * * @return */ public boolean isChildScrollToTop() { if (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); } }
/** * @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() { // //For make it can work when my recycler view is in Gone. // return false; 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); } }
private boolean canChildScrollUp(View mTarget) { if (mTarget == null) { return false; } if (android.os.Build.VERSION.SDK_INT < 14 && mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } if (mTarget instanceof ViewGroup) { int childCount = ((ViewGroup) mTarget).getChildCount(); for (int i = 0; i < childCount; i++) { View child = ((ViewGroup) mTarget).getChildAt(i); if (canChildScrollUp(child)) { return true; } } } return ViewCompat.canScrollVertically(mTarget, -1); }
/** * copy from {@link android.support.v4.widget.SwipeRefreshLayout#canChildScrollUp()} * * @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. */ protected boolean canChildScrollUp() { if (android.os.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); } }
/** * @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 (mChildView == null) { return false; } if (Build.VERSION.SDK_INT < 14) { if (mChildView instanceof AbsListView) { final AbsListView absListView = (AbsListView) mChildView; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } else { return ViewCompat.canScrollVertically(mChildView, -1) || mChildView.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mChildView, -1); } }
if (fristPos == 0 && absListView.getChildAt(0).getTop() >= absListView .getPaddingTop()) { return false;
/** * @param context Context to construct the view with * @param menuType LIST or GRID * @param title Title for the sheet. Can be null * @param listener Listener for menu item clicks in the sheet */ public MenuSheetView(final Context context, final MenuType menuType, @Nullable final CharSequence title, final OnMenuItemClickListener listener) { super(context); // Set up the menu this.menu = new MenuBuilder(context); this.menuType = menuType; // Inflate the appropriate view and set up the absListView inflate(context, menuType == GRID ? R.layout.grid_sheet_view : R.layout.list_sheet_view, this); absListView = (AbsListView) findViewById(menuType == GRID ? R.id.grid : R.id.list); if (listener != null) { absListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listener.onMenuItemClick(adapter.getItem(position).getMenuItem()); } }); } // Set up the title titleView = (TextView) findViewById(R.id.title); originalListPaddingTop = absListView.getPaddingTop(); setTitle(title); ViewCompat.setElevation(this, Util.dp2px(getContext(), 16f)); }
/** * 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; }
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; }
/** * 判断目标View是否滑动到顶部-还能否继续滑动 * * @return */ public boolean isChildScrollToTop() { if (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); } }
public boolean canContentViewScrollUp() { if (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 ViewCompat.canScrollVertically(contentView, -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 canChildPullDown() { if (child instanceof AbsListView) { final AbsListView absListView = (AbsListView) child; return canScrollVertically(child, -1) || absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView .getChildAt(0).getTop() < absListView .getPaddingTop()); } else { return canScrollVertically(child, -1) || child.getScrollY() > 0; } }
/** * @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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
/** * 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); } }
if (fristPos == 0 && absListView.getChildAt(0).getTop() >= absListView .getPaddingTop()) { return false;
@Override public int getScrollY() { int firstVisiblePosition = absListView.getFirstVisiblePosition(); View c = absListView.getChildAt(0); if (c == null) { return 0; } int top = c.getTop() - absListView.getPaddingTop(); return -top + firstVisiblePosition * c.getHeight(); } }
public int getScrollY(AbsListView mListView) { int padding = mListView.getPaddingTop(); View c = mListView.getChildAt(0); if (c == null) { return 0; } int firstVisiblePosition = mListView.getFirstVisiblePosition(); int top = c.getTop(); return -top + firstVisiblePosition * c.getHeight() + padding; } }
@Override public boolean canOverStart() { if (absListView.getCount() == 0) { return true; } else if (absListView.getFirstVisiblePosition() == 0 && absListView.getChildAt(0).getTop() >= absListView.getPaddingTop()) { return true; } return false; }