Android:如何获取ListView是否处于滚动模式?

标签 android android-listview scrollview

如果我的 ListView 不会处于滚动模式(因为屏幕上的项目很少),那么我想要它 android:stackFromBottom="false" 但如果我的 ListView 开始滚动(有足够的项目可以滚动),那么我想通过我的代码 android:stackFromBottom="true" 。我怎样才能过去?希望你能找到我。

最佳答案

比较 getLastVisiblePosition()getCount()在 Runnable 中查看整个 ListView 在绘制后是否适合屏幕。您还应该检查最后一个可见行是否完全适合屏幕。

创建可运行的:

ListView listView;
Runnable fitsOnScreen = new Runnable() {
    @Override
    public void run() {
        int last = listView.getLastVisiblePosition();
        if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
            // It fits!
        }
        else {
            // It doesn't fit...
        }
    }
};

onCreate() 中将您的 Runnable 放入 ListView 的处理程序中:

listView.post(fitsOnScreen);

关于Android:如何获取ListView是否处于滚动模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114747/

相关文章:

android - 在 View 顶部打开 PopupWindow

android - 为什么自定义 DialogPreference 不会在 onSharedPreferenceChanged 监听器上触发?

java - 滚动 AlphabetIndexer 时快速滚动拇指消失

android - 如何在 ListView 中显示不同的 json 字符串?

ios - 使用 UIWebView 滚动 UIImageView?

Android Error : java. io.IOException : CreateProcess error=2, 系统找不到指定的文件

android - notifyDataSetChanged() 不适合我

c++ - 动态扩展滚动条?

javascript - 如何在 Touchable 组件中包含 ScrollView?

android - 操作栏不显示操作 View 图标