我需要在我的列表视图中完全禁用过度滚动,这样我才能实现自己的过度滚动功能。
查看核心列表视图类时似乎很简单,只需将overscroll模式设置为 OVERSCROLL_NEVER。这在我的三星 Galaxy s2 上做得很好。但不起作用Galaxy Tab 2.3.3.
有没有人对可以帮助我的三星 ListView 自定义有很多经验?
我需要在我的列表视图中完全禁用过度滚动,这样我才能实现自己的过度滚动功能。
查看核心列表视图类时似乎很简单,只需将overscroll模式设置为 OVERSCROLL_NEVER。这在我的三星 Galaxy s2 上做得很好。但不起作用Galaxy Tab 2.3.3.
有没有人对可以帮助我的三星 ListView 自定义有很多经验?
它适用于三星 Galaxy Tab(使用 Android 2.2):
try {
    // list you want to disable overscroll
    // replace 'R.id.services' with your list id
    ListView listView = ((ListView)findViewById(R.id.services)); 
    // find the method
    Method setEnableExcessScroll =
            listView.getClass().getMethod("setEnableExcessScroll", Boolean.TYPE);
    // call the method with parameter set to false 
    setEnableExcessScroll.invoke(listView, Boolean.valueOf(false)); 
}
catch (SecurityException e) {}
catch (NoSuchMethodException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalAccessException e) {}
catch (InvocationTargetException e) {}
    您必须将列表视图的高度设置为固定值。如果您的内容是动态的,则有一个很好的函数可以在重置适配器后测量实际的列表大小:
    public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }
    int totalHeight = 0;
    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
设置适配器后,您必须使用列表视图作为参数调用此静态方法。您现在可以添加一个滚动视图(里面是您的列表视图和其他视图)。我会说 2.3.3 之前的这种行为是一个小错误......除了我描述的方式之外,没有简单的方法可以将列表视图包含在滚动视图中。出于这个原因,他们引入了 OVERSCROLL_NEVER 模式:)
代码来自 DougW!
不是我的解决方案,但对我有用:)