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

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

源代码1 项目: SmartSwipe   文件: ViewCompat.java
/**
 * Check if the items in the list can be scrolled in a certain direction.
 *
 * @param listView listView
 * @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.
 */
public static boolean canListViewScrollVertical(AbsListView listView, int direction) {
    if (Build.VERSION.SDK_INT >= 19) {
        // Call the framework version directly
        return listView.canScrollList(direction);
    } else {
        // provide backport on earlier versions
        final int childCount = listView.getChildCount();
        if (childCount == 0) {
            return false;
        }

        final int firstPosition = listView.getFirstVisiblePosition();
        if (direction > 0) {
            final int lastBottom = listView.getChildAt(childCount - 1).getBottom();
            final int lastPosition = firstPosition + childCount;
            return lastPosition < listView.getCount()
                    || (lastBottom > listView.getHeight() - listView.getListPaddingBottom());
        } else {
            final int firstTop = listView.getChildAt(0).getTop();
            return firstPosition > 0 || firstTop < listView.getListPaddingTop();
        }
    }
}
 
源代码2 项目: pius1   文件: SlideBottomPanel.java
/**
 * 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();
    }
}
 
源代码3 项目: Dashchan   文件: ExpandedScreen.java
@Override
public void onScroll(AbsListView view, int scrollY, int totalItemCount, boolean first, boolean last) {
	if (Math.abs(scrollY) > slopShiftSize) {
		scrollingDown = scrollY > 0;
	}
	boolean hide = false;
	if (scrollingDown) {
		if (totalItemCount > minItemsCount) {
			// List can be overscrolled when it shows first item including list top padding
			// top <= 0 means that list is not overscrolled
			if (!first || view.getChildAt(0).getTop() <= 0) {
				if (last) {
					View lastView = view.getChildAt(view.getChildCount() - 1);
					if (view.getHeight() - view.getPaddingBottom() - lastView.getBottom() + lastItemLimit < 0) {
						hide = true;
					}
				} else {
					hide = true;
				}
			}
		}
	}
	setShowActionBar(!hide, true);
}
 
源代码4 项目: AndroidMaterialDialog   文件: DialogRootView.java
/**
 * Returns, whether a specific list view is scrolled to the bottom, or not.
 *
 * @param scrollView 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 bottom, false otherwise
 */
private boolean isListViewScrolledToBottom(@NonNull final AbsListView scrollView) {
    if (scrollView.getCount() > 0 && scrollView.getChildCount() > 0) {
        if (scrollView.getLastVisiblePosition() == scrollView.getCount() - 1) {
            View child = scrollView.getChildAt(scrollView.getChildCount() - 1);
            return child == null || child.getBottom() <= scrollView.getHeight();
        }
    } else {
        return true;
    }

    return false;
}
 
源代码5 项目: Pix-Art-Messenger   文件: ConversationFragment.java
private static boolean scrolledToBottom(AbsListView listView) {
    final int count = listView.getCount();
    if (count == 0) {
        return true;
    } else if (listView.getLastVisiblePosition() == count - 1) {
        final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
        return lastChild != null && lastChild.getBottom() <= listView.getHeight();
    } else {
        return false;
    }
}
 
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    if (firstVisibleItem + visibleItemCount >= totalItemCount) {
        final View lastView = view.getChildAt(view.getChildCount() - 1);
        if (lastView != null) {
            translationY = footerView.getHeight() - (view.getHeight() - (ViewCompat.getY(lastView) + lastView.getHeight())) + (paddingBottom / 2);
            ViewCompat.setTranslationY(footerView, translationY);
        }
    } else {
        translationY = footerView.getHeight();
        ViewCompat.setTranslationY(footerView, translationY);
    }
}
 
源代码7 项目: Conversations   文件: ConversationFragment.java
private static boolean scrolledToBottom(AbsListView listView) {
    final int count = listView.getCount();
    if (count == 0) {
        return true;
    } else if (listView.getLastVisiblePosition() == count - 1) {
        final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
        return lastChild != null && lastChild.getBottom() <= listView.getHeight();
    } else {
        return false;
    }
}
 
源代码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 项目: ProjectX   文件: EdgeScrollListener.java
/**
 * 滚动更改
 *
 * @param view             AbsListView
 * @param firstVisibleItem 第一个可见子项
 * @param visibleItemCount 可见子项总数
 * @param totalItemCount   子项总数
 */
private void onScrollChanged(AbsListView view, int firstVisibleItem,
                             int visibleItemCount, int totalItemCount) {
    if (visibleItemCount != 0) {
        ScrollLocation mNewScrollLocation;
        final int gridTop = view.getPaddingTop();
        final int gridBottom = view.getHeight() - view.getPaddingBottom();
        if (totalItemCount == visibleItemCount) {
            // 头尾均显示,需判断是否可滚动
            final int childFristTop = view.getChildAt(0).getTop();
            final int childLastBottom = view.getChildAt(
                    visibleItemCount - 1).getBottom();
            if (childFristTop >= gridTop && childLastBottom <= gridBottom) {
                mNewScrollLocation = ScrollLocation.TB;
            } else if (childFristTop >= gridTop) {
                mNewScrollLocation = ScrollLocation.TOP;
            } else if (childLastBottom <= gridBottom) {
                mNewScrollLocation = ScrollLocation.BOTTOM;
            } else {
                mNewScrollLocation = ScrollLocation.CENTER;
            }

        } else {
            // 头尾不完全显示
            if (firstVisibleItem == 0) {
                // 头显示
                if (view.getChildAt(0).getTop() >= gridTop) {
                    mNewScrollLocation = ScrollLocation.TOP;
                } else {
                    mNewScrollLocation = ScrollLocation.CENTER;
                }

            } else if (firstVisibleItem + visibleItemCount == totalItemCount) {
                // 尾显示
                if (view.getChildAt(visibleItemCount - 1).getBottom() <= gridBottom) {
                    mNewScrollLocation = ScrollLocation.BOTTOM;
                } else {
                    mNewScrollLocation = ScrollLocation.CENTER;
                }
            } else {
                // 头尾均不显示
                mNewScrollLocation = ScrollLocation.CENTER;
            }
        }
        if (mScrollLocation != mNewScrollLocation) {
            if (mScrollLocation == ScrollLocation.NULL) {
                mScrollLocation = mNewScrollLocation;
                return;
            }
            onScrollLocationChanged(mNewScrollLocation, mScrollLocation);
            mScrollLocation = mNewScrollLocation;
        }
    }
}