我的listview在2台设备上的行为是,当我过度滚动它时,它会变成黄色/橙色,或者它可以被过度滚动然后快速回退.后一种行为很糟糕,因为它显示了我想要阻止的背后的背景.
我试过了:
listview.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
并且它不再显示背景,但现在有一种非常恼人的反弹效果.是否有可能同时禁用弹跳和过度滚动并使其滚动到达结束时刚刚结束而没有任何影响?
PS:我在两台设备上都使用android 2.3.
解决方法
这是我如何解决这个问题,希望它能帮助那些搜索.关键是将OnScrollListener附加到列表中,跟踪何时处理fling手势以及何时到达列表末尾.然后,在弹出仍在进行的同时,如果系统试图移动它,请继续将位置重置到最后.
private ListView mListView; private ListAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_list); mListView = (ListView) findViewById(R.id.listView); mAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,getList(25)); mListView.setAdapter(mAdapter); mListView.setOverScrollMode(View.OVER_SCROLL_NEVER); if(Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD || Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1){ mListView.setOnScrollListener(new OnScrollListener(){ private boolean flinging = false; private boolean reachedEnd = false; @Override public void onScrollStateChanged(AbsListView view,int scrollState) { flinging = (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING); reachedEnd = false; } @Override public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount) { if(reachedEnd && flinging && (firstVisibleItem + visibleItemCount < totalItemCount)){ mListView.setSelection(mAdapter.getCount() - 1); }else if(firstVisibleItem + visibleItemCount == totalItemCount){ reachedEnd = true; }else{ reachedEnd = false; } } }); } }