我需要在我的列表视图中完全禁用overscroll,这样我就可以实现我自己的overscroll功能。
在查看核心listview类时,只需将overscroll模式设置为OVERSCROLL_NEVER,似乎就足够简单了。在我的三星盖乐世s2上的这件精美作品。但不适用于Galaxy Tab 2.3.3.
有没有人有很多使用三星ListView定制的经验,可以帮助我?
发布于 2012-04-23 01:11:46
您必须将listview的高度设置为固定值。如果您的内容是动态的,那么有一个很好的函数可以在重置适配器后测量实际的列表大小:
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();
}在设置适配器后,您必须使用listview作为参数来调用此静态方法。你现在可以添加一个滚动视图(里面是你的列表视图和其他视图)。我想说2.3.3和更早的版本中的这个行为是一个小错误……除了我所描述的方法之外,没有简单的方法可以在scrollview中包含listview。出于这个原因,他们引入了OVERSCROLL_NEVER模式:)
代码来自DougW!
发布于 2012-08-17 23:36:02
我在三星Galaxy Tab (安卓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) {}发布于 2013-11-23 01:49:12
不是我的解决方案,但适用于我:)
https://stackoverflow.com/questions/10161232
复制相似问题