How to check if a my ListView has scrollable number of items?

后端 未结 8 670
故里飘歌
故里飘歌 2020-12-30 04:00

How do you know if your ListView has enough number of items so that it can scroll?

For instance, If I have 5 items on my ListView all of it will be displayed on a si

8条回答
  •  滥情空心
    2020-12-30 04:44

    AbsListView includes this:

    /**
     * Check if the items in the list can be scrolled in a certain direction.
     *
     * @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.
     * @see #scrollListBy(int)
     */
    public boolean canScrollList(int direction);
    

    You need to override layoutChildren() and use it within that:

    @Override
    protected void layoutChildren() {
        super.layoutChildren();
        isAtBottom = !canScrollList(1);
        isAtTop = !canScrollList(-1);
    }
    

提交回复
热议问题