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

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

private static boolean performAbsListView(AbsListView view, int direction) {
    int childCount = view.getChildCount();
    if (childCount > 0) {
        switch (direction) {
            case DIRECTION_DOWN:
                ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
                int firstItemTop = view.getChildAt(0).getTop();
                int listViewTop = view.getTop() + view.getPaddingTop() - lp.topMargin;
                if (DEBUG_SCROLL_CHECK)
                    L.e(TAG, "firstItemTop=%s,listViewTop=%s", firstItemTop, listViewTop);
                return (view.getFirstVisiblePosition() > 0
                        || firstItemTop < listViewTop);
            case DIRECTION_UP:
                int lastItemBottom = view.getChildAt(childCount - 1).getBottom();
                int listViewBottom = view.getBottom() - view.getPaddingBottom();
                if (DEBUG_SCROLL_CHECK)
                    L.e(TAG, "lastItemBottom=%s,listViewBottom=%s", lastItemBottom, listViewBottom);
                return (view.getLastVisiblePosition() < childCount - 1
                        || lastItemBottom > listViewBottom);
        }
    }
    if (DEBUG_SCROLL_CHECK)
        L.e(TAG, "AbsListView cannot scroll vertically or childCount is 0!!");
    return false;
}
 
/**
 * @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 (mOnChildScrollUpCallback != null) {
        return mOnChildScrollUpCallback.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);
    }
}
 
源代码3 项目: Elephant   文件: PtrDefaultHandler2.java
public static boolean canChildScrollDown(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else if (view instanceof ScrollView) {
            ScrollView scrollView = (ScrollView) view;
            if (scrollView.getChildCount() == 0) {
                return false;
            } else {
                return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight();
            }
        } else {
            return false;
        }
    } else {
        return view.canScrollVertically(1);
    }
}
 
源代码4 项目: weex-uikit   文件: WXSwipeLayout.java
/**
 * Whether child view can scroll down
 * @return
 */
public boolean canChildScrollDown() {
  if (mTargetView == null) {
    return false;
  }
  if (Build.VERSION.SDK_INT < 14) {
    if (mTargetView instanceof AbsListView) {
      final AbsListView absListView = (AbsListView) mTargetView;
      if (absListView.getChildCount() > 0) {
        int lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1)
            .getBottom();
        return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1
               && lastChildBottom <= absListView.getMeasuredHeight();
      } else {
        return false;
      }

    } else {
      return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
    }
  } else {
    return ViewCompat.canScrollVertically(mTargetView, 1);
  }
}
 
源代码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 项目: FamilyChat   文件: CommonPtrLayout.java
private boolean canScrollDown(View view)
{
    if (android.os.Build.VERSION.SDK_INT < 14)
    {
        if (view instanceof AbsListView)
        {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else
        {
            return ViewCompat.canScrollVertically(view, 1) || view.getScrollY() < 0;
        }
    } else
    {
        return ViewCompat.canScrollVertically(view, 1);
    }
}
 
/**
 * Utility method to check whether a {@link View} can scroll up from it's current position.
 * Handles platform version differences, providing backwards compatible functionality where
 * needed.
 */
private static boolean canViewScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(view, -1);
    } else {
        if (view instanceof AbsListView) {
            // Pre-ICS we need to manually check the first visible item and the child view's top
            // value
            final AbsListView listView = (AbsListView) view;
            return listView.getChildCount() > 0 &&
                    (listView.getFirstVisiblePosition() > 0
                            || listView.getChildAt(0).getTop() < listView.getPaddingTop());
        } else {
            // For all other view types we just check the getScrollY() value
            return view.getScrollY() > 0;
        }
    }
}
 
源代码8 项目: dynamiclistview   文件: Util.java
public static boolean reachedListBottom(AbsListView listView) {
	boolean flag = true;
	if (listView.getChildCount() != 0) {
		int i = listView.getLastVisiblePosition();
		int j = listView.getCount();
		int k = listView.getHeight();
		int l = listView.getChildAt(-1 + listView.getChildCount()).getBottom();
		if (i != j - 1 || l > k) {
			flag = false;
		}
	}
	return flag;
}
 
源代码9 项目: 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);
    }
}
 
源代码10 项目: AgentWebX5   文件: ScrollingUtil.java
/**
 * Whether it is possible for the child view of this layout to scroll down. Override this if the child view is a custom view.
 * 判断是否可以上拉
 */
public static boolean canChildScrollDown(View mChildView) {
    if (Build.VERSION.SDK_INT < 14) {
        if (mChildView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mChildView;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mChildView, 1) || mChildView.getScrollY() < 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mChildView, 1);
    }
}
 
源代码11 项目: AutoRecycleView   文件: SuperSwipeRefreshLayout.java
/**
 * 判断目标View是否滑动到顶部-还能否继续滑动
 *
 * @return
 */
public boolean isChildScrollToTop() {
    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);
    }
}
 
源代码12 项目: anvil-examples   文件: StartView.java
public void onScroll(AbsListView v, int first, int count, int total) {
	int top = 0;
	if (v.getChildCount() > 0) {
		top = -v.getChildAt(0).getTop() + first * v.getChildAt(0).getHeight();
		if (top >= 0) {
			mTopViewHeight = Math.max((int) (Style.MAX_TOP_HEIGHT - top/(getResources().getDisplayMetrics().density)/1.5f), Style.MIN_TOP_HEIGHT);
		}
	}
}
 
源代码13 项目: SimpleProject   文件: ScrollStateUtil.java
/**
 * AbsListView类型的View是否已滑动到底部
 * @param listView
 * @return
 */
public static boolean absListViewReachBottom(AbsListView listView) {
	if (listView.getChildCount() > 0) {
		int lastItemBottom = listView.getChildAt(listView.getChildCount() - 1).getBottom();
		int listHeight = listView.getBottom() - listView.getTop();
		return listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1
				&& lastItemBottom <= listHeight;
	}

	return false;
}
 
源代码14 项目: android-recipes-app   文件: 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);
    }
}
 
源代码15 项目: stynico   文件: SlidingLayout.java
/**
 * 判断View是否可以上拉
 * @return canChildScrollUp
 */
public boolean canChildScrollUp() {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        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);
    }
}
 
源代码16 项目: stynico   文件: SlidingLayout.java
/**
 * 判断View是否可以下拉
 * @return canChildScrollDown
 */
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mTargetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTargetView;
            return absListView.getChildCount() > 0 && absListView.getAdapter() != null
                    && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1)
                    .getBottom() < absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTargetView, 1);
    }
}
 
源代码17 项目: AndroidStudyDemo   文件: BGARefreshLayout.java
public boolean shouldHandleAbsListViewLoadingMore(AbsListView absListView) {
    if (mIsLoadingMore || mCurrentRefreshStatus == RefreshStatus.REFRESHING || mLoadMoreFooterView == null || mDelegate == null || absListView == null ||  absListView.getAdapter() == null || absListView.getAdapter().getCount() == 0) {
        return false;
    }

    int lastChildBottom = 0;
    if (absListView.getChildCount() > 0) {
        // 如果AdapterView的子控件数量不为0,获取最后一个子控件的bottom
        lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1).getBottom();
    }
    return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1 && lastChildBottom <= absListView.getMeasuredHeight();
}
 
源代码18 项目: LLApp   文件: SlidingLayout.java
/**
 * 判断View是否可以下拉
 * @return canChildScrollDown
 */
public boolean canChildScrollDown() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mTargetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTargetView;
            return absListView.getChildCount() > 0 && absListView.getAdapter() != null
                    && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1)
                    .getBottom() < absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTargetView, 1);
    }
}
 
源代码19 项目: 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);
    }
}
 
源代码20 项目: direct-select-android   文件: DSListView.java
@Override
public void onScroll(AbsListView listView, int firstVisible, int visibleItemCount, int totalItemCount) {
    if (!pickerInitialized || !selectorAnimationsEnabled) return;

    int selectorPosY = cellHeight * cellsBeforeSelector;
    int applyingRangeY = cellHeight;

    for (int i = 0; i < listView.getChildCount(); i++) {

        // Exclude elements that does not need to edit
        if (!(listView.getChildAt(i) instanceof FrameLayout))
            continue;

        ViewGroup itemRoot = (ViewGroup) listView.getChildAt(i);

        float deviation = 2f;
        if (itemRoot.getTop() > selectorPosY + applyingRangeY * deviation || itemRoot.getTop() < selectorPosY - applyingRangeY * deviation)
            continue;

        View cellContent = itemRoot.getChildAt(0);

        // Edit elements regarding to their position from selector
        float dy = Math.abs(itemRoot.getTop() - selectorPosY);
        if (!selectorAnimationCenterPivot) {
            cellContent.setPivotX(0);
            cellContent.setPivotY(cellContent.getHeight() / 2);
        }

        // Scale and "3d effect" for big scale factors on API>=LOLLIPOP
        if (dy <= applyingRangeY) {
            float k1 = 1 - (dy / applyingRangeY);
            float scale = 1 + scaleFactorDelta * k1;
            cellContent.setScaleX(scale);
            cellContent.setScaleY(scale);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                itemRoot.setZ((dy <= applyingRangeY / 2) ? 2 : 1);

        } else {
            cellContent.setScaleX(1f);
            cellContent.setScaleY(1f);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                itemRoot.setZ(0);
        }

    }
}